From 11077ac16f68d49d4fd08817255385f428338d7c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 6 Aug 2009 09:18:49 +0000 Subject: Add unicode conversions in various logging code. svn path=/main/trunk/; revision=13931 --- pym/portage/elog/messages.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'pym/portage/elog') diff --git a/pym/portage/elog/messages.py b/pym/portage/elog/messages.py index 9832f2660..3b44e0fe8 100644 --- a/pym/portage/elog/messages.py +++ b/pym/portage/elog/messages.py @@ -79,15 +79,23 @@ def _elog_base(level, msg, phase="other", key=None, color=None, out=None): global _msgbuffer - if color == None: + if out is None: + out = sys.stdout + + if color is None: color = "GOOD" + if not isinstance(msg, unicode): + msg = unicode(msg, encoding='utf_8', errors='replace') + formatted_msg = colorize(color, " * ") + msg + "\n" - if out is None: - sys.stdout.write(formatted_msg) - else: - out.write(formatted_msg) + if sys.hexversion < 0x3000000 and \ + out in (sys.stdout, sys.stderr) and isinstance(formatted_msg, unicode): + # avoid potential UnicodeEncodeError + formatted_msg = formatted_msg.encode('utf_8', 'replace') + + out.write(formatted_msg) if key not in _msgbuffer: _msgbuffer[key] = {} -- cgit v1.2.3-1-g7c22