Use _unicode_encode() to ensure that only unicode strings are passed into
authorZac Medico <zmedico@gentoo.org>
Sun, 20 Sep 2009 20:00:57 +0000 (20:00 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 20 Sep 2009 20:00:57 +0000 (20:00 -0000)
io.StringIO text streams.

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

pym/_emerge/JobStatusDisplay.py
pym/portage/output.py

index dd72a29714f58570cef0069a38d9ab7b731c64cb..7cf3607fb2d6b09b1f6094aa06cec721b7aca04c 100644 (file)
@@ -10,6 +10,7 @@ from io import StringIO
 import portage
 from portage import os
 from portage import _encodings
+from portage import _unicode_decode
 from portage.output import xtermTitle
 
 from _emerge.getloadavg import getloadavg
@@ -222,36 +223,36 @@ class JobStatusDisplay(object):
                f = formatter.AbstractFormatter(style_writer)
 
                number_style = "INFORM"
-               f.add_literal_data("Jobs: ")
+               f.add_literal_data(_unicode_decode("Jobs: "))
                f.push_style(number_style)
-               f.add_literal_data(curval_str)
+               f.add_literal_data(_unicode_decode(curval_str))
                f.pop_style()
-               f.add_literal_data(" of ")
+               f.add_literal_data(_unicode_decode(" of "))
                f.push_style(number_style)
-               f.add_literal_data(maxval_str)
+               f.add_literal_data(_unicode_decode(maxval_str))
                f.pop_style()
-               f.add_literal_data(" complete")
+               f.add_literal_data(_unicode_decode(" complete"))
 
                if self.running:
-                       f.add_literal_data(", ")
+                       f.add_literal_data(_unicode_decode(", "))
                        f.push_style(number_style)
-                       f.add_literal_data(running_str)
+                       f.add_literal_data(_unicode_decode(running_str))
                        f.pop_style()
-                       f.add_literal_data(" running")
+                       f.add_literal_data(_unicode_decode(" running"))
 
                if self.failed:
-                       f.add_literal_data(", ")
+                       f.add_literal_data(_unicode_decode(", "))
                        f.push_style(number_style)
-                       f.add_literal_data(failed_str)
+                       f.add_literal_data(_unicode_decode(failed_str))
                        f.pop_style()
-                       f.add_literal_data(" failed")
+                       f.add_literal_data(_unicode_decode(" failed"))
 
                padding = self._jobs_column_width - len(plain_output.getvalue())
                if padding > 0:
-                       f.add_literal_data(padding * " ")
+                       f.add_literal_data(padding * _unicode_decode(" "))
 
-               f.add_literal_data("Load avg: ")
-               f.add_literal_data(load_avg_str)
+               f.add_literal_data(_unicode_decode("Load avg: "))
+               f.add_literal_data(_unicode_decode(load_avg_str))
 
                # Truncate to fit width, to avoid making the terminal scroll if the
                # line overflows (happens when the load average is large).
index 5170d70aabbd1f6f6c40e389ff5b3af2a014a119..a85647c4d4734c1ef0b1329866e2df60827e11b8 100644 (file)
@@ -22,6 +22,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
 from portage import os
 from portage import _encodings
 from portage import _unicode_encode
+from portage import _unicode_decode
 from portage.const import COLOR_MAP_FILE
 from portage.exception import CommandNotFound, FileNotFound, \
        ParseError, PermissionDenied, PortageException
@@ -743,6 +744,12 @@ def _init(config_root='/'):
        codes = object.__getattribute__(codes, '_attr')
        _styles = object.__getattribute__(_styles, '_attr')
 
+       for k, v in codes.iteritems():
+               codes[k] = _unicode_decode(v)
+
+       for k, v in _styles.iteritems():
+               _styles[k] = _unicode_decode(v)
+
        try:
                _parse_color_map(config_root=config_root,
                        onerror=lambda e: writemsg("%s\n" % str(e), noiselevel=-1))