Set the encoding to 'utf_8', if the encoding returned by
authorPaul Varner <fuzzyray@gentoo.org>
Sat, 1 Jan 2011 17:38:55 +0000 (11:38 -0600)
committerPaul Varner <fuzzyray@gentoo.org>
Sat, 1 Jan 2011 17:38:55 +0000 (11:38 -0600)
locale.getpreferredencoding() is unknown to python. (Bug 350156)

pym/gentoolkit/pprinter.py

index 7ab60dcf96e9bed3c6da29fe915304842c344fa0..d9f0375742524a20b21f78b92c901be490f2bff9 100644 (file)
@@ -36,6 +36,7 @@ __all__ = (
 
 import sys
 import locale
+import codecs
 
 import portage.output as output
 from portage import archlist
@@ -169,6 +170,14 @@ def uprint(*args, **kw):
        file = getattr(file, 'buffer', file)
 
        encoding = locale.getpreferredencoding()
+       # Make sure that python knows the encoding. Bug 350156
+       try:
+               # We don't care about what is returned, we just want to
+               # verify that we can find a codec.
+               codecs.lookup(encoding)
+       except LookupError:
+               # Python does not know the encoding, so use utf-8.
+               encoding = 'utf_8'
 
        def encoded_args():
                for arg in args: