Don't encode the env in py3k since it expects strings for the env that's
authorZac Medico <zmedico@gentoo.org>
Mon, 21 Sep 2009 20:12:40 +0000 (20:12 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 21 Sep 2009 20:12:40 +0000 (20:12 -0000)
passed into os.execve().

svn path=/main/trunk/; revision=14363

pym/portage/process.py

index 428c66f4cb51432f7702839426adc288c57f3664..68c523a09e627404945ee31b6106630e470b8d7e 100644 (file)
@@ -188,13 +188,14 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
        if isinstance(mycommand, basestring):
                mycommand = mycommand.split()
 
-       # Avoid a potential UnicodeEncodeError from os.execve().
-       env_bytes = {}
-       for k, v in env.items():
-               env_bytes[_unicode_encode(k, encoding=_encodings['content'])] = \
-                       _unicode_encode(v, encoding=_encodings['content'])
-       env = env_bytes
-       del env_bytes
+       if sys.hexversion < 0x3000000:
+               # Avoid a potential UnicodeEncodeError from os.execve().
+               env_bytes = {}
+               for k, v in env.items():
+                       env_bytes[_unicode_encode(k, encoding=_encodings['content'])] = \
+                               _unicode_encode(v, encoding=_encodings['content'])
+               env = env_bytes
+               del env_bytes
 
        # If an absolute path to an executable file isn't given
        # search for it unless we've been told not to.
@@ -373,13 +374,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask,
        if pre_exec:
                pre_exec()
 
-       # Decode all keys for compatibility with Python 3.
-       env_decoded = {}
-       for k, v in env.items():
-               env_decoded[_unicode_decode(k)] = v
-
        # And switch to the new process.
-       os.execve(binary, myargs, env_decoded)
+       os.execve(binary, myargs, env)
 
 def find_binary(binary):
        """