In grablines(), specify encoding=sys.getdefaultencoding() in the codecs.open()
authorZac Medico <zmedico@gentoo.org>
Mon, 20 Jul 2009 18:57:18 +0000 (18:57 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 20 Jul 2009 18:57:18 +0000 (18:57 -0000)
parameters, since otherwise readlines doesn't return unicode (at least in
some cases, observed with python-2.6.2). Also, fix grabfile() to return
unicode when it normalizes whitespace.

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

pym/portage/util.py

index 4ccd512aed74050560db88683a86fd541c8a20d7..6d9a23cd1a15940d2a4ccca6befaba1ffb1ee1e9 100644 (file)
@@ -103,7 +103,7 @@ def grabfile(myfilename, compat_level=0, recursive=0):
        for x in mylines:
                #the split/join thing removes leading and trailing whitespace, and converts any whitespace in the line
                #into single spaces.
-               myline=" ".join(x.split())
+               myline = u' '.join(x.split())
                if not len(myline):
                        continue
                if myline[0]=="#":
@@ -317,7 +317,8 @@ def grablines(myfilename,recursive=0):
                                        os.path.join(myfilename, f), recursive))
        else:
                try:
-                       myfile = codecs.open(myfilename, mode='r', errors='replace')
+                       myfile = codecs.open(myfilename, mode='r',
+                               encoding=sys.getdefaultencoding(), errors='replace')
                        mylines = myfile.readlines()
                        myfile.close()
                except IOError, e: