Python 3.1: pass bytes to Popen
authorZac Medico <zmedico@gentoo.org>
Sat, 22 Jun 2013 19:33:50 +0000 (12:33 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 22 Jun 2013 19:33:50 +0000 (12:33 -0700)
commitdd8ead757b3dcfc1b84037b28f215db3ecc6b800
treee8b277188b0d0d820455d7a182d773a285323080
parent30fe6f117ce0350c6b6d1279bae63508a8abbf59
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)
bin/install.py
bin/repoman
pym/portage/__init__.py
pym/portage/_emirrordist/FetchTask.py
pym/portage/checksum.py
pym/portage/data.py
pym/portage/dispatch_conf.py
pym/portage/tests/lint/test_bash_syntax.py
pym/portage/util/__init__.py
pym/portage/util/_desktop_entry.py
pym/repoman/utilities.py