From 2b5cf6a3b096ab728212a210075bd1f4d173dac0 Mon Sep 17 00:00:00 2001 From: Paul Varner Date: Sat, 1 Jan 2011 11:38:55 -0600 Subject: [PATCH] Set the encoding to 'utf_8', if the encoding returned by locale.getpreferredencoding() is unknown to python. (Bug 350156) --- pym/gentoolkit/pprinter.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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: -- 2.26.2