diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-06 09:18:49 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-06 09:18:49 +0000 |
commit | 11077ac16f68d49d4fd08817255385f428338d7c (patch) | |
tree | 70b8c7a9460d294cf19f2b125cf6040869580fed /pym/portage/elog | |
parent | Convert paths to unicode when working with CONTENTS. (diff) | |
download | portage-11077ac16f68d49d4fd08817255385f428338d7c.tar.gz portage-11077ac16f68d49d4fd08817255385f428338d7c.tar.bz2 portage-11077ac16f68d49d4fd08817255385f428338d7c.zip |
Add unicode conversions in various logging code.
svn path=/main/trunk/; revision=13931
Diffstat (limited to 'pym/portage/elog')
-rw-r--r-- | pym/portage/elog/messages.py | 18 |
1 files changed, 13 insertions, 5 deletions
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] = {} |