diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-07 08:31:39 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-07 08:31:39 +0000 |
commit | cfeb7f4273946bb5f67dcf0b9de403bd20fa1875 (patch) | |
tree | 1ce65deef1e4c7b97812721da7620161c8d9169a | |
parent | 40932fc85440f9fd5952829913c327ad3bfee722 (diff) | |
download | portage-cfeb7f4273946bb5f67dcf0b9de403bd20fa1875.tar.gz portage-cfeb7f4273946bb5f67dcf0b9de403bd20fa1875.tar.bz2 portage-cfeb7f4273946bb5f67dcf0b9de403bd20fa1875.zip |
Convert environment variables to unicode inside the config constructor, in
order to avoid potential UnicodeDecodeError exceptions later.
svn path=/main/trunk/; revision=13945
-rw-r--r-- | pym/portage/__init__.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 8b9ac9012..276f8852d 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -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 |