Index: Lib/genericpath.py =================================================================== --- Lib/genericpath.py (révision 80494) +++ Lib/genericpath.py (copie de travail) @@ -104,3 +104,11 @@ filenameIndex += 1 return p, p[:0] + +def fsdecode(path): + """Decode a path from the file system encoding""" + return path + +def fsencode(path): + """Encode a path to the file system encoding""" + return path Index: Lib/posixpath.py =================================================================== --- Lib/posixpath.py (révision 80494) +++ Lib/posixpath.py (copie de travail) @@ -451,3 +451,21 @@ if not rel_list: return curdir return join(*rel_list) + +def fsdecode(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 fsencode(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 80494) +++ Lib/ntpath.py (copie de travail) @@ -609,3 +609,17 @@ if not rel_list: return _get_dot(path) return join(*rel_list) + +def fsdecode(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 fsencode(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 80494) +++ Lib/macpath.py (copie de travail) @@ -199,4 +199,22 @@ pass return path +def fsdecode(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 fsencode(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 80494) +++ Lib/subprocess.py (copie de travail) @@ -1079,32 +1079,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.fsencode(k) + b'=' + os.path.fsencode(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.fsencode(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.fsencode(exe) for exe in executable_list) self.pid = _posixsubprocess.fork_exec( args, executable_list,