Update imports to import portage.os (with unicode wrappers), and use
authorZac Medico <zmedico@gentoo.org>
Wed, 12 Aug 2009 00:54:03 +0000 (00:54 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 12 Aug 2009 00:54:03 +0000 (00:54 -0000)
_unicode_encode() and _unicode_decode() where appropriate.

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

pym/portage/__init__.py
pym/portage/manifest.py

index 2325297b43fbc55b617c771254b7251e0bc2e584..f4fb04890b4a881ef037b4ea49c5bf1a48a2cffe 100644 (file)
@@ -104,8 +104,6 @@ try:
                INVALID_ENV_FILE, CUSTOM_MIRRORS_FILE, CONFIG_MEMORY_FILE,\
                INCREMENTALS, EAPI, MISC_SH_BINARY, REPO_NAME_LOC, REPO_NAME_FILE
 
-       from portage.manifest import Manifest
-       import portage.exception
        from portage.localization import _
 
 except ImportError, e:
@@ -188,6 +186,8 @@ os = _unicode_module_wrapper(os)
 import shutil
 shutil = _unicode_module_wrapper(shutil)
 
+# Imports below this point rely on the above unicode wrapper definitions.
+
 try:
        import portage._selinux as selinux
 except OSError, e:
@@ -196,6 +196,8 @@ except OSError, e:
 except ImportError:
        pass
 
+from portage.manifest import Manifest
+
 # ===========================================================================
 # END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END OF IMPORTS -- END
 # ===========================================================================
index a717d584194f5f395c9212eae64b3843b2fc233a..e411be8c199b03d0a7a4bb4d678b0e61c44bb39f 100644 (file)
@@ -2,7 +2,8 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Id$
 
-import errno, os
+import codecs
+import errno
 
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
@@ -10,7 +11,12 @@ portage.proxy.lazyimport.lazyimport(globals(),
        'portage.util:write_atomic',
 )
 
-from portage.exception import *
+from portage import os
+from portage import _unicode_decode
+from portage import _unicode_encode
+from portage.exception import DigestException, FileNotFound, \
+       InvalidDataType, MissingParameter, PermissionDenied, \
+       PortageException, PortagePackageException
 
 class FileNotInManifestException(PortageException):
        pass
@@ -93,7 +99,7 @@ class Manifest(object):
                    Do not parse Manifest file if from_scratch == True (only for internal use)
                        The fetchlist_dict parameter is required only for generation of
                        a Manifest (not needed for parsing and checking sums)."""
-               self.pkgdir = pkgdir.rstrip(os.sep) + os.sep
+               self.pkgdir = _unicode_decode(pkgdir).rstrip(os.sep) + os.sep
                self.fhashdict = {}
                self.hashes = set()
                self.hashes.update(portage.const.MANIFEST2_HASH_FUNCTIONS)
@@ -135,7 +141,8 @@ class Manifest(object):
                """Parse a manifest.  If myhashdict is given then data will be added too it.
                   Otherwise, a new dict will be created and returned."""
                try:
-                       fd = open(file_path, "r")
+                       fd = codecs.open(_unicode_encode(file_path), mode='r',
+                               encoding='utf_8', errors='replace')
                        if myhashdict is None:
                                myhashdict = {}
                        self._parseDigests(fd, myhashdict=myhashdict, **kwargs)
@@ -221,7 +228,8 @@ class Manifest(object):
                        update_manifest = True
                        if not force:
                                try:
-                                       f = open(self.getFullname(), "r")
+                                       f = codecs.open(_unicode_encode(self.getFullname()),
+                                               mode='r', encoding='utf_8', errors='replace')
                                        oldentries = list(self._parseManifestLines(f))
                                        f.close()
                                        if len(oldentries) == len(myentries):
@@ -308,14 +316,11 @@ class Manifest(object):
                cat = self._pkgdir_category()
 
                pkgdir = self.pkgdir
-               if isinstance(pkgdir, unicode):
-                       # Avoid UnicodeDecodeError raised from
-                       # os.path.join when called by os.walk.
-                       pkgdir = pkgdir.encode('utf_8', 'replace')
 
                for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(pkgdir):
                        break
                for f in pkgdir_files:
+                       f = _unicode_decode(f)
                        if f[:1] == ".":
                                continue
                        pf = None
@@ -343,11 +348,6 @@ class Manifest(object):
                recursive_files = []
 
                pkgdir = self.pkgdir
-               if isinstance(pkgdir, unicode):
-                       # Avoid UnicodeDecodeError raised from
-                       # os.path.join when called by os.walk.
-                       pkgdir = pkgdir.encode('utf_8', 'replace')
-
                cut_len = len(os.path.join(pkgdir, "files") + os.sep)
                for parentdir, dirs, files in os.walk(os.path.join(pkgdir, "files")):
                        for f in files:
@@ -508,7 +508,8 @@ class Manifest(object):
                mfname = self.getFullname()
                if not os.path.exists(mfname):
                        return rVal
-               myfile = open(mfname, "r")
+               myfile = codecs.open(_unicode_encode(mfname),
+                       mode='r', encoding='utf_8', errors='replace')
                lines = myfile.readlines()
                myfile.close()
                for l in lines: