From fbcf09a5d4dc3c72af6767d221ce1c1c0375e686 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 11 Mar 2009 05:51:57 +0000 Subject: [PATCH] For compatibility with python-3.0, always open streams for pickles in binary mode. (trunk r12641) svn path=/main/branches/2.1.6/; revision=12913 --- pym/_emerge/__init__.py | 14 +++----------- pym/portage/__init__.py | 5 ++--- pym/portage/dbapi/vartree.py | 5 ++--- pym/portage/getbinpkg.py | 9 +++++---- pym/portage/util.py | 3 +-- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index e52298f54..df6b3c80f 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -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): diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 68a6f63f9..5326a0acd 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -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 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index f9da7ad07..90785459a 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -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 diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index d42b51781..89252d4b8 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -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: diff --git a/pym/portage/util.py b/pym/portage/util.py index 2b5a1f214..35c4e2c0c 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -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 -- 2.26.2