Make spawn decode unicode in order to avoid a potential UnicodeEncodeError
authorZac Medico <zmedico@gentoo.org>
Fri, 7 Aug 2009 08:21:56 +0000 (08:21 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 7 Aug 2009 08:21:56 +0000 (08:21 -0000)
from os.execve().

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

pym/portage/process.py

index a88f5bf28f24699f968a815d556b3c47a22843ea..051a59f618fb1c6d3bb948c2148331d0b7fb0033 100644 (file)
@@ -178,6 +178,17 @@ 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.iteritems():
+               if isinstance(k, unicode):
+                       k = k.encode('utf_8', 'replace')
+               if isinstance(v, unicode):
+                       v = v.encode('utf_8', 'replace')
+               env_bytes[k] = v
+       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.
        binary = mycommand[0]