summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-06 09:27:54 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-06 09:27:54 +0000
commitf8cdc4e505651733d7e1809ac4a0167a3bd2e282 (patch)
treeffdb703554a2302cace97d9fd25db6ffa3d094be
parent11077ac16f68d49d4fd08817255385f428338d7c (diff)
downloadportage-f8cdc4e505651733d7e1809ac4a0167a3bd2e282.tar.gz
portage-f8cdc4e505651733d7e1809ac4a0167a3bd2e282.tar.bz2
portage-f8cdc4e505651733d7e1809ac4a0167a3bd2e282.zip
Convert unicode if necessary before writing to stdout.
svn path=/main/trunk/; revision=13932
-rw-r--r--pym/_emerge/JobStatusDisplay.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/pym/_emerge/JobStatusDisplay.py b/pym/_emerge/JobStatusDisplay.py
index 561b78c2d..97d2a33f2 100644
--- a/pym/_emerge/JobStatusDisplay.py
+++ b/pym/_emerge/JobStatusDisplay.py
@@ -73,6 +73,13 @@ class JobStatusDisplay(object):
temporarily overridden stdout."""
return sys.stdout
+ def _write(self, s):
+ if sys.hexversion < 0x3000000 and isinstance(s, unicode):
+ # avoid potential UnicodeEncodeError
+ s = s.encode('utf_8', 'replace')
+ self.out.write(s)
+ self.out.flush()
+
def _init_term(self):
"""
Initialize term control codes.
@@ -110,23 +117,19 @@ class JobStatusDisplay(object):
return ">>> %s" % msg
def _erase(self):
- self.out.write(
+ self._write(
self._term_codes['carriage_return'] + \
self._term_codes['clr_eol'])
- self.out.flush()
self._displayed = False
def _display(self, line):
- self.out.write(line)
- self.out.flush()
+ self._write(line)
self._displayed = True
def _update(self, msg):
- out = self.out
if not self._isatty:
- out.write(self._format_msg(msg) + self._term_codes['newline'])
- self.out.flush()
+ self._write(self._format_msg(msg) + self._term_codes['newline'])
self._displayed = True
return
@@ -142,8 +145,7 @@ class JobStatusDisplay(object):
if self._isatty and self._displayed:
self._erase()
- self.out.write(self._format_msg(msg) + self._term_codes['newline'])
- self.out.flush()
+ self._write(self._format_msg(msg) + self._term_codes['newline'])
self._displayed = False
if was_displayed:
@@ -157,8 +159,7 @@ class JobStatusDisplay(object):
object.__setattr__(self, name, 0)
if self._displayed:
- self.out.write(self._term_codes['newline'])
- self.out.flush()
+ self._write(self._term_codes['newline'])
self._displayed = False
def __setattr__(self, name, value):