Bug #282269, comment #2 - Avoid potential UnicodeEncodeError when writing
authorZac Medico <zmedico@gentoo.org>
Sat, 22 Aug 2009 19:28:35 +0000 (19:28 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 22 Aug 2009 19:28:35 +0000 (19:28 -0000)
to sys.stderr inside xtermTitle().

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

pym/portage/output.py

index 0e016c5c66b0f03f39aaa3abf314064b66b5363e..637535b0ba230987baabc878edae285d840c220d 100644 (file)
@@ -252,6 +252,9 @@ def xtermTitle(mystr, raw=False):
                        mystr = mystr[:_max_xtermTitle_len]
                if not raw:
                        mystr = '\x1b]0;%s\x07' % mystr
+               if sys.hexversion < 0x3000000 and isinstance(mystr, unicode):
+                       # avoid potential UnicodeEncodeError
+                       mystr = mystr.encode(_encodings['stdio'], 'backslashreplace')
                sys.stderr.write(mystr)
                sys.stderr.flush()