summaryrefslogtreecommitdiffstats
path: root/pym/portage/output.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-10-26 22:26:31 +0000
committerZac Medico <zmedico@gentoo.org>2009-10-26 22:26:31 +0000
commitad9e5fe8a557b1cb0b54aeb5268eb209abfaf0c8 (patch)
tree65d16296bca818bddadb9583d709059449ce0beb /pym/portage/output.py
parent403624a789efd1476a1a00a5c9808a5c1e8fe830 (diff)
downloadportage-ad9e5fe8a557b1cb0b54aeb5268eb209abfaf0c8.tar.gz
portage-ad9e5fe8a557b1cb0b54aeb5268eb209abfaf0c8.tar.bz2
portage-ad9e5fe8a557b1cb0b54aeb5268eb209abfaf0c8.zip
Bug #290625 - Manually encode output to stdout in python3, in order to avoid
potential UnicodeEncodeError exceptions. svn path=/main/trunk/; revision=14734
Diffstat (limited to 'pym/portage/output.py')
-rw-r--r--pym/portage/output.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/pym/portage/output.py b/pym/portage/output.py
index 6044f2bbc..6d4e108aa 100644
--- a/pym/portage/output.py
+++ b/pym/portage/output.py
@@ -251,11 +251,15 @@ 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()
+
+ # avoid potential UnicodeEncodeError
+ mystr = _unicode_encode(mystr,
+ encoding=_encodings['stdio'], errors='backslashreplace')
+ f = sys.stderr
+ if sys.hexversion >= 0x3000000:
+ f = f.buffer
+ f.write(mystr)
+ f.flush()
default_xterm_title = None
@@ -374,11 +378,12 @@ class ConsoleStyleFile(object):
self._write(self.write_listener, s)
def _write(self, f, s):
- if sys.hexversion < 0x3000000 and \
- isinstance(s, unicode) and \
- f in (sys.stdout, sys.stderr):
- # avoid potential UnicodeEncodeError
- s = s.encode(_encodings['stdio'], 'backslashreplace')
+ # avoid potential UnicodeEncodeError
+ if f in (sys.stdout, sys.stderr):
+ s = _unicode_encode(s,
+ encoding=_encodings['stdio'], errors='backslashreplace')
+ if sys.hexversion >= 0x3000000:
+ f = f.buffer
f.write(s)
def writelines(self, lines):
@@ -484,9 +489,12 @@ class EOutput(object):
sys.stderr.flush()
def _write(self, f, s):
- if sys.hexversion < 0x3000000 and isinstance(s, unicode):
- # avoid potential UnicodeEncodeError
- s = s.encode(_encodings['stdio'], 'backslashreplace')
+ # avoid potential UnicodeEncodeError
+ s = _unicode_encode(s,
+ encoding=_encodings['stdio'], errors='backslashreplace')
+ f = sys.stderr
+ if sys.hexversion >= 0x3000000:
+ f = f.buffer
f.write(s)
f.flush()