For compatibility with python-3.0, always open streams for pickles in binary
authorZac Medico <zmedico@gentoo.org>
Thu, 19 Feb 2009 10:14:13 +0000 (10:14 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 19 Feb 2009 10:14:13 +0000 (10:14 -0000)
mode.

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

pym/_emerge/__init__.py
pym/portage/__init__.py
pym/portage/dbapi/vartree.py
pym/portage/getbinpkg.py
pym/portage/util.py

index 830a6d5b4a0b3d313430e90e1e7acd9e636c509f..413792606e11070ce6021fe620b5ba440917faee 100644 (file)
@@ -4043,9 +4043,8 @@ class BlockerCache(portage.cache.mappings.MutableMapping):
 
        def _load(self):
                try:
-                       f = open(self._cache_filename)
+                       f = open(self._cache_filename, mode='rb')
                        mypickle = pickle.Unpickler(f)
-                       mypickle.find_global = None
                        self._cache_data = mypickle.load()
                        f.close()
                        del f
@@ -4129,7 +4128,7 @@ class BlockerCache(portage.cache.mappings.MutableMapping):
                if len(self._modified) >= self._cache_threshold and \
                        secpass >= 2:
                        try:
-                               f = portage.util.atomic_ofstream(self._cache_filename)
+                               f = portage.util.atomic_ofstream(self._cache_filename, mode='wb')
                                pickle.dump(self._cache_data, f, -1)
                                f.close()
                                portage.util.apply_secpass_permissions(
@@ -14423,14 +14422,7 @@ def action_build(settings, trees, mtimedb,
                        # a list type for options.
                        mtimedb["resume"]["myopts"] = myopts.copy()
 
-                       # Convert Atom instances to plain str since the mtimedb loader
-                       # sets unpickler.find_global = None which causes unpickler.load()
-                       # to raise the following exception:
-                       #
-                       # cPickle.UnpicklingError: Global and instance pickles are not supported.
-                       #
-                       # TODO: Maybe stop setting find_global = None, or find some other
-                       # way to avoid accidental triggering of the above UnpicklingError.
+                       # Convert Atom instances to plain str.
                        mtimedb["resume"]["favorites"] = [str(x) for x in favorites]
 
                        if ("--digest" in myopts) and not ("--fetchonly" in myopts or "--fetch-all-uri" in myopts):
index fa4e721be5377fb639c29e373b963ef39449f2ba..9769f3607053aca2c6ca6e609b31c9a26b859404 100644 (file)
@@ -7439,7 +7439,7 @@ def commit_mtimedb(mydict=None, filename=None):
        d = {} # for full backward compat, pickle it as a plain dict object.
        d.update(mydict)
        try:
-               f = atomic_ofstream(filename)
+               f = atomic_ofstream(filename, mode='wb')
                pickle.dump(d, f, -1)
                f.close()
                portage.util.apply_secpass_permissions(filename, uid=uid, gid=portage_gid, mode=0664)
@@ -7604,9 +7604,8 @@ class MtimeDB(dict):
 
        def _load(self, filename):
                try:
-                       f = open(filename)
+                       f = open(filename, 'rb')
                        mypickle = pickle.Unpickler(f)
-                       mypickle.find_global = None
                        d = mypickle.load()
                        f.close()
                        del f
index b7cee710c9601dd41f437d62db9e612c59fc9958..14c5360e2b4211bb9c4451c6cc7e776a02dba174 100644 (file)
@@ -58,7 +58,7 @@ class PreservedLibsRegistry(object):
        def load(self):
                """ Reload the registry data from file """
                try:
-                       self._data = pickle.load(open(self._filename, "r"))
+                       self._data = pickle.load(open(self._filename, 'rb'))
                except (EOFError, IOError), e:
                        if isinstance(e, EOFError) or e.errno == errno.ENOENT:
                                self._data = {}
@@ -75,7 +75,7 @@ class PreservedLibsRegistry(object):
                        self._data == self._data_orig:
                        return
                try:
-                       f = atomic_ofstream(self._filename)
+                       f = atomic_ofstream(self._filename, 'wb')
                        pickle.dump(self._data, f)
                        f.close()
                except EnvironmentError, e:
@@ -1027,7 +1027,7 @@ class vardbapi(dbapi):
                                        del self._aux_cache["packages"][cpv]
                        del self._aux_cache["modified"]
                        try:
-                               f = atomic_ofstream(self._aux_cache_filename)
+                               f = atomic_ofstream(self._aux_cache_filename, 'wb')
                                pickle.dump(self._aux_cache, f, -1)
                                f.close()
                                apply_secpass_permissions(
@@ -1045,9 +1045,8 @@ class vardbapi(dbapi):
        def _aux_cache_init(self):
                aux_cache = None
                try:
-                       f = open(self._aux_cache_filename)
+                       f = open(self._aux_cache_filename, 'rb')
                        mypickle = pickle.Unpickler(f)
-                       mypickle.find_global = None
                        aux_cache = mypickle.load()
                        f.close()
                        del f
index d42b517814cd0964c8584ec42694c9292f1a7b01..89252d4b892a46f1771ad21d9c7f8b2e8ba02ccd 100644 (file)
@@ -471,6 +471,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                keepconnection = 1
 
        cache_path = "/var/cache/edb"
+       metadatafilename = os.path.join(cache_path, 'remote_metadata.pickle')
 
        if makepickle is None:
                makepickle = "/var/cache/edb/metadata.idx.most_recent"
@@ -485,7 +486,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
 
        out = sys.stdout
        try:
-               metadatafile = open("/var/cache/edb/remote_metadata.pickle")
+               metadatafile = open(metadatafilename, 'rb')
                metadata = pickle.load(metadatafile)
                out.write("Loaded metadata pickle.\n")
                out.flush()
@@ -574,7 +575,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
                                        sys.stderr.write("!!! "+str(e)+"\n")
                                        sys.stderr.flush()
                        try:
-                               metadatafile = open("/var/cache/edb/remote_metadata.pickle", "w+")
+                               metadatafile = open(metadatafilename, 'wb')
                                pickle.dump(metadata,metadatafile)
                                metadatafile.close()
                        except SystemExit, e:
@@ -666,11 +667,11 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache=
        try:
                if "modified" in metadata[baseurl] and metadata[baseurl]["modified"]:
                        metadata[baseurl]["timestamp"] = int(time.time())
-                       metadatafile = open("/var/cache/edb/remote_metadata.pickle", "w+")
+                       metadatafile = open(metadatafilename, 'wb')
                        pickle.dump(metadata,metadatafile)
                        metadatafile.close()
                if makepickle:
-                       metadatafile = open(makepickle, "w")
+                       metadatafile = open(makepickle, 'wb')
                        pickle.dump(metadata[baseurl]["data"],metadatafile)
                        metadatafile.close()
        except SystemExit, e:
index 2b5a1f21455b706e0ddfaeaffdf983da28043a86..35c4e2c0cdb06148da77dc300ef266b335120518 100644 (file)
@@ -657,9 +657,8 @@ def pickle_read(filename,default=None,debug=0):
                return default
        data = None
        try:
-               myf = open(filename)
+               myf = open(filename, 'rb')
                mypickle = pickle.Unpickler(myf)
-               mypickle.find_global = None
                data = mypickle.load()
                myf.close()
                del mypickle,myf