Convert environment variables to unicode inside the config constructor, in
authorZac Medico <zmedico@gentoo.org>
Fri, 7 Aug 2009 08:31:39 +0000 (08:31 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 7 Aug 2009 08:31:39 +0000 (08:31 -0000)
order to avoid potential UnicodeDecodeError exceptions later.

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

pym/portage/__init__.py

index 8b9ac90127a0409f2f85e1fb6d8a4bfe917c51ba..276f8852dcf9d4123c8e1396944f9cd19c47053e 100644 (file)
@@ -1519,7 +1519,17 @@ class config(object):
                        # backupenv is used for calculating incremental variables.
                        if env is None:
                                env = os.environ
-                       self.backupenv = env.copy()
+
+                       # Avoid potential UnicodeDecodeError exceptions later.
+                       env_unicode = {}
+                       for k, v in env.iteritems():
+                               if not isinstance(k, unicode):
+                                       k = unicode(k, encoding='utf_8', errors='replace')
+                               if not isinstance(v, unicode):
+                                       v = unicode(v, encoding='utf_8', errors='replace')
+                               env_unicode[k] = v
+
+                       self.backupenv = env_unicode
 
                        if env_d:
                                # Remove duplicate values so they don't override updated