Avoid UnicodeEncodeError in writemsg(). Thanks to Markos Chandras
authorZac Medico <zmedico@gentoo.org>
Tue, 4 Aug 2009 18:09:46 +0000 (18:09 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 4 Aug 2009 18:09:46 +0000 (18:09 -0000)
<hwoarang@gentoo.org> for reporting.

svn path=/main/trunk/; revision=13900

pym/portage/util.py

index 49eec6492c6bc69fe9ef34c05e7bbc8b53947d83..f1bff1d4086869e51bf6bb6274240c30aaf77e4b 100644 (file)
@@ -56,6 +56,9 @@ def writemsg(mystr,noiselevel=0,fd=None):
        if fd is None:
                fd = sys.stderr
        if noiselevel <= noiselimit:
+               if sys.hexversion < 0x3000000 and isinstance(mystr, unicode):
+                       # avoid potential UnicodeEncodeError
+                       mystr = mystr.encode('utf_8', 'replace')
                fd.write(mystr)
                fd.flush()