Python 3.1: pass bytes to Popen
For Python 3.1, it's possible to pass bytes to Popen as long as the
executable has an absolute path, since otherwise we would trigger a
TypeError in os._execvp (see http://bugs.python.org/issue8513).
Note that Python <=3.1.3 produces the following message:
TypeError: expected an object with the buffer interface
Later 3.1.x releases produce a different message:
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
The difference in messages is due to os.path.join() implementation
changes, but both errors are triggered by the same underlying bug in
os._execvp() which was fixed by using fsencode() in this hunk:
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -355,7 +355,11 @@ def _execvpe(file, args, env=None):
return
last_exc = saved_exc = None
saved_tb = None
- for dir in get_exec_path(env):
+ path_list = get_exec_path(env)
+ if name != 'nt':
+ file = fsencode(file)
+ path_list = map(fsencode, path_list)
+ for dir in path_list:
fullname = path.join(dir, file)