Make getconfig() use codecs.option() for py3k compatible unicode handling.
authorZac Medico <zmedico@gentoo.org>
Sat, 4 Jul 2009 19:25:42 +0000 (19:25 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 4 Jul 2009 19:25:42 +0000 (19:25 -0000)
svn path=/main/trunk/; revision=13780

pym/portage/util.py

index d57b1bc3545af807cdc190a27cf3c979d6bd597c..1da4b4ba289a69760f5f861b85a7b97b1391b978 100644 (file)
@@ -12,6 +12,7 @@ __all__ = ['apply_permissions', 'apply_recursive_permissions',
        'unique_array', 'varexpand', 'write_atomic', 'writedict', 'writemsg',
        'writemsg_level', 'writemsg_stdout']
 
+import codecs
 import os
 import errno
 import logging
@@ -366,7 +367,10 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
                # Workaround for avoiding a silent error in shlex that
                # is triggered by a source statement at the end of the file without a
                # trailing newline after the source statement
-               f = StringIO("\n".join(open(mycfg, 'r').readlines()) + "\n")
+               content = codecs.open(mycfg, mode='r', errors='replace').read()
+               if content[-1] != u'\n':
+                       content += u'\n'
+               f = StringIO(content)
        except IOError, e:
                if e.errno == PermissionDenied.errno:
                        raise PermissionDenied(mycfg)