From: Zac Medico Date: Thu, 6 Aug 2009 09:27:54 +0000 (-0000) Subject: Convert unicode if necessary before writing to stdout. X-Git-Tag: v2.2_rc37~34 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f8cdc4e505651733d7e1809ac4a0167a3bd2e282;p=portage.git Convert unicode if necessary before writing to stdout. svn path=/main/trunk/; revision=13932 --- 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):