From: Zac Medico Date: Mon, 20 Jul 2009 18:57:18 +0000 (-0000) Subject: In grablines(), specify encoding=sys.getdefaultencoding() in the codecs.open() X-Git-Tag: v2.2_rc34~35 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=42dbc8067534ae2f8183a6bc69202fb08c81a4aa;p=portage.git In grablines(), specify encoding=sys.getdefaultencoding() in the codecs.open() 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 --- diff --git a/pym/portage/util.py b/pym/portage/util.py index 4ccd512ae..6d9a23cd1 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -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: