From ad9e5fe8a557b1cb0b54aeb5268eb209abfaf0c8 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 26 Oct 2009 22:26:31 +0000 Subject: Bug #290625 - Manually encode output to stdout in python3, in order to avoid potential UnicodeEncodeError exceptions. svn path=/main/trunk/; revision=14734 --- pym/portage/elog/messages.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'pym/portage/elog') diff --git a/pym/portage/elog/messages.py b/pym/portage/elog/messages.py index a563ad271..b2a2dc4cf 100644 --- a/pym/portage/elog/messages.py +++ b/pym/portage/elog/messages.py @@ -96,11 +96,12 @@ def _elog_base(level, msg, phase="other", key=None, color=None, out=None): formatted_msg = colorize(color, " * ") + msg + "\n" - if sys.hexversion < 0x3000000 and \ - out in (sys.stdout, sys.stderr) and isinstance(formatted_msg, unicode): - # avoid potential UnicodeEncodeError - formatted_msg = formatted_msg.encode( - _encodings['stdio'], 'backslashreplace') + # avoid potential UnicodeEncodeError + if out in (sys.stdout, sys.stderr): + formatted_msg = _unicode_encode(formatted_msg, + encoding=_encodings['stdio'], errors='backslashreplace') + if sys.hexversion >= 0x3000000: + out = out.buffer out.write(formatted_msg) -- cgit v1.2.3-1-g7c22