From: Paul Varner Date: Sat, 1 Jan 2011 17:38:55 +0000 (-0600) Subject: Set the encoding to 'utf_8', if the encoding returned by X-Git-Tag: gentoolkit-0.3.0~43 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2b5cf6a3b096ab728212a210075bd1f4d173dac0;p=gentoolkit.git Set the encoding to 'utf_8', if the encoding returned by locale.getpreferredencoding() is unknown to python. (Bug 350156) --- diff --git a/pym/gentoolkit/pprinter.py b/pym/gentoolkit/pprinter.py index 7ab60dc..d9f0375 100644 --- a/pym/gentoolkit/pprinter.py +++ b/pym/gentoolkit/pprinter.py @@ -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: