For compatibility with python-3.0, always open streams for pickles in binary
authorZac Medico <zmedico@gentoo.org>
Wed, 11 Mar 2009 05:51:57 +0000 (05:51 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 11 Mar 2009 05:51:57 +0000 (05:51 -0000)
mode. (trunk r12641)

svn path=/main/branches/2.1.6/; revision=12913

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

index e52298f54d4522f8a25e9ef212ad300461d9b5c7..df6b3c80ff1f8cc5af3f9afd974e30b113201217 100644 (file)
@@ -4027,9 +4027,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
@@ -4113,7 +4112,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(
@@ -14069,14 +14068,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 68a6f63f92a0140f599e0aed2d474e396747fa38..5326a0acd4d0b3faa64be3f1d1ed9ce52d252cb0 100644 (file)
@@ -7426,7 +7426,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)
@@ -7591,9 +7591,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 f9da7ad0769460766753fc8aaefb53af7b582775..90785459a7ebea55088153d1b7c871b1e815e880 100644 (file)
@@ -372,7 +372,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(
@@ -390,9 +390,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