Index: Lib/os.py =================================================================== --- Lib/os.py (révision 80421) +++ Lib/os.py (copie de travail) @@ -355,6 +355,8 @@ return last_exc = saved_exc = None saved_tb = None + if isinstance(file, bytes): + file = file.decode(sys.getfilesystemencoding(), 'surrogateescape') for dir in get_exec_path(env): fullname = path.join(dir, file) try: @@ -380,7 +382,13 @@ """ if env is None: env = environ - return env.get('PATH', defpath).split(pathsep) + if 'PATH' in env: + path = env['PATH'] + if isinstance(path, bytes): + path = path.decode(sys.getfilesystemencoding(), 'surrogateescape') + else: + path = defpath + return path.split(pathsep) # Change environ to automatically call putenv(), unsetenv if they exist. Index: Lib/test/test_subprocess.py =================================================================== --- Lib/test/test_subprocess.py (révision 80424) +++ Lib/test/test_subprocess.py (copie de travail) @@ -827,7 +827,21 @@ stdout = stdout.rstrip(b'\n\r') self.assertEquals(stdout, value_repr) + def fs_encode(self, filename): + return filename.encode(sys.getfilesystemencoding(), "surrogateescape") + def test_bytes_program(self): + path, program = os.path.split(sys.executable) + path = self.fs_encode(path) + program = self.fs_encode(program) + env = os.environ.copy() + env["PATH"] = path + exitcode = subprocess.call( + [program, "-c", "pass"], + env=env) + self.assertEquals(exitcode, 0) + + @unittest.skipUnless(mswindows, "Windows specific tests") class Win32ProcessTestCase(BaseTestCase): Index: Lib/subprocess.py =================================================================== --- Lib/subprocess.py (révision 80421) +++ Lib/subprocess.py (copie de travail) @@ -1088,6 +1088,11 @@ if _posixsubprocess: fs_encoding = sys.getfilesystemencoding() + def fs_decode(s): + if isinstance(s, str): + return s + else: + return s.decode(fs_encoding, 'surrogateescape') def fs_encode(s): """Encode s for use in the env, fs or cmdline.""" if isinstance(s, bytes): @@ -1110,7 +1115,8 @@ else: # This matches the behavior of os._execvpe(). path_list = os.get_exec_path(env) - executable_list = (os.path.join(dir, executable) + executable_str = fs_decode(executable) + executable_list = (os.path.join(dir, executable_str) for dir in path_list) executable_list = tuple(fs_encode(exe) for exe in executable_list)