diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-09 22:54:00 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-09 22:54:00 +0000 |
commit | 26e20aad7f60e344a3826138af8934c2174c6b4c (patch) | |
tree | 9c06af4f7ed3ca42efeabf56ebbeb0744046fda6 | |
parent | 2428fe1ceed45b69fe882ed1c8e1cd8738b33c78 (diff) | |
download | portage-26e20aad7f60e344a3826138af8934c2174c6b4c.tar.gz portage-26e20aad7f60e344a3826138af8934c2174c6b4c.tar.bz2 portage-26e20aad7f60e344a3826138af8934c2174c6b4c.zip |
Fix EOutput to safely write unicode to stderr/stdout. Thanks to Arfrever for
reporting.
svn path=/main/trunk/; revision=13964
-rw-r--r-- | pym/portage/output.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/pym/portage/output.py b/pym/portage/output.py index eb0d247b7..8c6eb2ce0 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -466,6 +466,13 @@ class EOutput(object): sys.stdout.flush() sys.stderr.flush() + def _write(self, f, s): + if sys.hexversion < 0x3000000 and isinstance(s, unicode): + # avoid potential UnicodeEncodeError + s = s.encode('utf_8', 'replace') + f.write(s) + f.flush() + def __eend(self, caller, errno, msg): if errno == 0: status_brackets = colorize("BRACKET", "[ ") + colorize("GOOD", "ok") + colorize("BRACKET", " ]") @@ -480,9 +487,9 @@ class EOutput(object): self.__last_e_len = 0 if not self.quiet: out = sys.stdout - out.write("%*s%s\n" % ((self.term_columns - self.__last_e_len - 6), + self._write(out, + "%*s%s\n" % ((self.term_columns - self.__last_e_len - 6), "", status_brackets)) - out.flush() def ebegin(self, msg): """ @@ -524,9 +531,8 @@ class EOutput(object): out = sys.stderr if not self.quiet: if self.__last_e_cmd == "ebegin": - out.write("\n") - out.write(colorize("BAD", " * ") + msg + "\n") - out.flush() + self._write(out, "\n") + self._write(out, colorize("BAD", " * ") + msg + "\n") self.__last_e_cmd = "eerror" def einfo(self, msg): @@ -539,9 +545,8 @@ class EOutput(object): out = sys.stdout if not self.quiet: if self.__last_e_cmd == "ebegin": - out.write("\n") - out.write(colorize("GOOD", " * ") + msg + "\n") - out.flush() + self._write(out, "\n") + self._write(out, colorize("GOOD", " * ") + msg + "\n") self.__last_e_cmd = "einfo" def einfon(self, msg): @@ -554,9 +559,8 @@ class EOutput(object): out = sys.stdout if not self.quiet: if self.__last_e_cmd == "ebegin": - out.write("\n") - out.write(colorize("GOOD", " * ") + msg) - out.flush() + self._write(out, "\n") + self._write(out, colorize("GOOD", " * ") + msg) self.__last_e_cmd = "einfon" def ewarn(self, msg): @@ -569,9 +573,8 @@ class EOutput(object): out = sys.stderr if not self.quiet: if self.__last_e_cmd == "ebegin": - out.write("\n") - out.write(colorize("WARN", " * ") + msg + "\n") - out.flush() + self._write(out, "\n") + self._write(out, colorize("WARN", " * ") + msg + "\n") self.__last_e_cmd = "ewarn" def ewend(self, errno, *msg): |