Misc unicode fixes for repoman.
authorZac Medico <zmedico@gentoo.org>
Sun, 20 Sep 2009 22:08:22 +0000 (22:08 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 20 Sep 2009 22:08:22 +0000 (22:08 -0000)
svn path=/main/trunk/; revision=14302

pym/portage/output.py
pym/repoman/utilities.py

index a85647c4d4734c1ef0b1329866e2df60827e11b8..c21dc07ba778d0d59840bf43e63af307fc62db44 100644 (file)
@@ -355,6 +355,11 @@ class ConsoleStyleFile(object):
                self._styles = styles
 
        def write(self, s):
+               # In python-2.6, DumbWriter.send_line_break() can write
+               # non-unicode '\n' which fails with TypeError if self._file
+               # is a text stream such as io.StringIO. Therefore, make sure
+               # input is converted to unicode when necessary.
+               s = _unicode_decode(s)
                global havecolor
                if havecolor and self._styles:
                        for style in self._styles:
index fcabd599db8a24553ceff96ff308ef551760d430..3d8d43aed7a080aeb0c1d930fa56ec3029d9899a 100644 (file)
@@ -33,6 +33,7 @@ from xml.dom import NotFoundErr
 from xml.parsers.expat import ExpatError
 from portage import os
 from portage import _encodings
+from portage import _unicode_decode
 from portage import _unicode_encode
 from portage import output
 from portage.output import red, green
@@ -221,12 +222,12 @@ def format_qa_output(formatter, stats, fails, dofull, dofail, options, qawarning
        # we only want key value pairs where value > 0 
        for category, number in \
                itertools.ifilter(lambda myitem: myitem[1] > 0, stats.iteritems()):
-               formatter.add_literal_data("  " + category.ljust(30))
+               formatter.add_literal_data(_unicode_decode("  " + category.ljust(30)))
                if category in qawarnings:
                        formatter.push_style("WARN")
                else:
                        formatter.push_style("BAD")
-               formatter.add_literal_data(str(number))
+               formatter.add_literal_data(_unicode_decode(str(number)))
                formatter.pop_style()
                formatter.add_line_break()
                if not dofull:
@@ -237,7 +238,7 @@ def format_qa_output(formatter, stats, fails, dofull, dofail, options, qawarning
                        if not full and len(fails_list) > 12:
                                fails_list = fails_list[:12]
                        for failure in fails_list:
-                               formatter.add_literal_data("   " + failure)
+                               formatter.add_literal_data(_unicode_decode("   " + failure))
                                formatter.add_line_break()
 
 
@@ -276,13 +277,17 @@ def get_commit_message_with_editor(editor, message=None):
        from tempfile import mkstemp
        fd, filename = mkstemp()
        try:
-               os.write(fd, "\n# Please enter the commit message " + \
+               os.write(fd, _unicode_encode(
+                       "\n# Please enter the commit message " + \
                        "for your changes.\n# (Comment lines starting " + \
-                       "with '#' will not be included)\n")
+                       "with '#' will not be included)\n",
+                       encoding=_encodings['content'], errors='backslashreplace'))
                if message:
-                       os.write(fd, "#\n")
+                       os.write(fd, _unicode_encode("#\n",
+                               encoding=_encodings['content'], errors='backslashreplace'))
                        for line in message:
-                               os.write(fd, "#" + line)
+                               os.write(fd, _unicode_encode("#" + line,
+                                       encoding=_encodings['content'], errors='backslashreplace'))
                os.close(fd)
                retval = os.system(editor + " '%s'" % filename)
                if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK):