Index: Lib/genericpath.py =================================================================== --- Lib/genericpath.py (révision 80417) +++ Lib/genericpath.py (copie de travail) @@ -104,3 +104,12 @@ filenameIndex += 1 return p, p[:0] + +def fs_decode(path): + """Decode a path from the file system encoding""" + return path + +def fs_encode(path): + """Encode a path to the file system encoding""" + return path + Index: Lib/posixpath.py =================================================================== --- Lib/posixpath.py (révision 80417) +++ Lib/posixpath.py (copie de travail) @@ -451,3 +451,22 @@ if not rel_list: return curdir return join(*rel_list) + +def fs_decode(path): + """Decode a path from the file system encoding""" + if isinstance(path, str): + return path + elif isinstance(path, bytes): + return path.decode(sys.getfilesystemencoding(), 'surrogateescape') + else: + raise TypeError("invalid filename type: %s" % type(path).__name__) + +def fs_encode(path): + """Encode a path to the file system encoding""" + if isinstance(path, bytes): + return path + elif isinstance(path, str): + return path.encode(sys.getfilesystemencoding(), 'surrogateescape') + else: + raise TypeError("invalid filename type: %s" % type(path).__name__) + Index: Lib/ntpath.py =================================================================== --- Lib/ntpath.py (révision 80417) +++ Lib/ntpath.py (copie de travail) @@ -609,3 +609,18 @@ if not rel_list: return _get_dot(path) return join(*rel_list) + +def fs_decode(path): + """Decode a path from the file system encoding""" + if isinstance(path, str): + return path + else: + raise TypeError("invalid filename type: %s" % type(path).__name__) + +def fs_encode(path): + """Encode a path to the file system encoding""" + if isinstance(path, str): + return path + else: + raise TypeError("invalid filename type: %s" % type(path).__name__) + Index: Lib/macpath.py =================================================================== --- Lib/macpath.py (révision 80417) +++ Lib/macpath.py (copie de travail) @@ -199,4 +199,22 @@ pass return path +def fs_decode(path): + """Decode a path from the file system encoding""" + if isinstance(path, str): + return path + elif isinstance(path, bytes): + return path.decode(sys.getfilesystemencoding()) + else: + raise TypeError("invalid filename type: %s" % type(path).__name__) + +def fs_encode(path): + """Encode a path to the file system encoding""" + if isinstance(path, bytes): + return path + elif isinstance(path, str): + return path.encode(sys.getfilesystemencoding()) + else: + raise TypeError("invalid filename type: %s" % type(path).__name__) + supports_unicode_filenames = False Index: Lib/subprocess.py =================================================================== --- Lib/subprocess.py (révision 80421) +++ Lib/subprocess.py (copie de travail) @@ -1087,32 +1087,24 @@ self._set_cloexec_flag(errpipe_write) if _posixsubprocess: - fs_encoding = sys.getfilesystemencoding() - def fs_encode(s): - """Encode s for use in the env, fs or cmdline.""" - if isinstance(s, bytes): - return s - else: - return s.encode(fs_encoding, 'surrogateescape') - # We must avoid complex work that could involve # malloc or free in the child process to avoid # potential deadlocks, thus we do all this here. # and pass it to fork_exec() if env: - env_list = [fs_encode(k) + b'=' + fs_encode(v) + env_list = [os.path.fs_encode(k) + b'=' + os.path.fs_encode(v) for k, v in env.items()] else: env_list = None # Use execv instead of execve. if os.path.dirname(executable): - executable_list = (fs_encode(executable),) + executable_list = (os.path.fs_encode(executable),) else: # This matches the behavior of os._execvpe(). path_list = os.get_exec_path(env) executable_list = (os.path.join(dir, executable) for dir in path_list) - executable_list = tuple(fs_encode(exe) + executable_list = tuple(os.path.fs_encode(exe) for exe in executable_list) self.pid = _posixsubprocess.fork_exec( args, executable_list,