From: Zac Medico Date: Tue, 23 Sep 2008 20:04:09 +0000 (-0000) Subject: Import cPickle as pickle instead of vice versa. Eases 2to3's job because X-Git-Tag: v2.2_rc10~20 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a997a5d7b3a2c48da4468dbf577497b5c39592c5;p=portage.git Import cPickle as pickle instead of vice versa. Eases 2to3's job because cPickle won't exist in py3k and 2to3 does s/cPickle/pickle. Thanks to Ali Polatel for this patch. svn path=/main/trunk/; revision=11536 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 6b1ac46d2..8122b0839 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -73,9 +73,9 @@ from itertools import chain, izip from UserDict import DictMixin try: - import cPickle + import cPickle as pickle except ImportError: - import pickle as cPickle + import pickle try: import cStringIO as StringIO @@ -3659,13 +3659,13 @@ class BlockerCache(DictMixin): def _load(self): try: f = open(self._cache_filename) - mypickle = cPickle.Unpickler(f) + mypickle = pickle.Unpickler(f) mypickle.find_global = None self._cache_data = mypickle.load() f.close() del f - except (IOError, OSError, EOFError, cPickle.UnpicklingError), e: - if isinstance(e, cPickle.UnpicklingError): + except (IOError, OSError, EOFError, pickle.UnpicklingError), e: + if isinstance(e, pickle.UnpicklingError): writemsg("!!! Error loading '%s': %s\n" % \ (self._cache_filename, str(e)), noiselevel=-1) del e @@ -3745,7 +3745,7 @@ class BlockerCache(DictMixin): secpass >= 2: try: f = portage.util.atomic_ofstream(self._cache_filename) - cPickle.dump(self._cache_data, f, -1) + pickle.dump(self._cache_data, f, -1) f.close() portage.util.apply_secpass_permissions( self._cache_filename, gid=portage.portage_gid, mode=0644) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 79d99f813..4e88931d7 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -20,9 +20,9 @@ try: import shutil import time try: - import cPickle + import cPickle as pickle except ImportError: - import pickle as cPickle + import pickle import stat import commands @@ -7025,7 +7025,7 @@ def commit_mtimedb(mydict=None, filename=None): d.update(mydict) try: f = atomic_ofstream(filename) - cPickle.dump(d, f, -1) + pickle.dump(d, f, -1) f.close() portage.util.apply_secpass_permissions(filename, uid=uid, gid=portage_gid, mode=0664) except (IOError, OSError), e: @@ -7179,13 +7179,13 @@ class MtimeDB(dict): def _load(self, filename): try: f = open(filename) - mypickle = cPickle.Unpickler(f) + mypickle = pickle.Unpickler(f) mypickle.find_global = None d = mypickle.load() f.close() del f - except (IOError, OSError, EOFError, cPickle.UnpicklingError), e: - if isinstance(e, cPickle.UnpicklingError): + except (IOError, OSError, EOFError, pickle.UnpicklingError), e: + if isinstance(e, pickle.UnpicklingError): writemsg("!!! Error loading '%s': %s\n" % \ (filename, str(e)), noiselevel=-1) del e diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 56e084028..f5c0e2b17 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -37,9 +37,9 @@ import shlex from itertools import izip try: - import cPickle + import cPickle as pickle except ImportError: - import pickle as cPickle + import pickle class PreservedLibsRegistry(object): """ This class handles the tracking of preserved library objects """ @@ -57,7 +57,7 @@ class PreservedLibsRegistry(object): def load(self): """ Reload the registry data from file """ try: - self._data = cPickle.load(open(self._filename, "r")) + self._data = pickle.load(open(self._filename, "r")) except (EOFError, IOError), e: if isinstance(e, EOFError) or e.errno == errno.ENOENT: self._data = {} @@ -74,7 +74,7 @@ class PreservedLibsRegistry(object): return try: f = atomic_ofstream(self._filename) - cPickle.dump(self._data, f) + pickle.dump(self._data, f) f.close() except EnvironmentError, e: if e.errno != PermissionDenied.errno: @@ -956,7 +956,7 @@ class vardbapi(dbapi): del self._aux_cache["modified"] try: f = atomic_ofstream(self._aux_cache_filename) - cPickle.dump(self._aux_cache, f, -1) + pickle.dump(self._aux_cache, f, -1) f.close() apply_secpass_permissions( self._aux_cache_filename, gid=portage_gid, mode=0644) @@ -974,13 +974,13 @@ class vardbapi(dbapi): aux_cache = None try: f = open(self._aux_cache_filename) - mypickle = cPickle.Unpickler(f) + mypickle = pickle.Unpickler(f) mypickle.find_global = None aux_cache = mypickle.load() f.close() del f - except (IOError, OSError, EOFError, cPickle.UnpicklingError), e: - if isinstance(e, cPickle.UnpicklingError): + except (IOError, OSError, EOFError, pickle.UnpicklingError), e: + if isinstance(e, pickle.UnpicklingError): writemsg("!!! Error loading '%s': %s\n" % \ (self._aux_cache_filename, str(e)), noiselevel=-1) del e diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index da0dd77ad..cd1bd0dc1 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -15,9 +15,9 @@ import base64 import urllib2 try: - import cPickle + import cPickle as pickle except ImportError: - import pickle as cPickle + import pickle try: import ftplib @@ -473,11 +473,11 @@ 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") - metadata = cPickle.load(metadatafile) + metadata = pickle.load(metadatafile) out.write("Loaded metadata pickle.\n") out.flush() metadatafile.close() - except (cPickle.UnpicklingError, OSError, IOError, EOFError): + except (pickle.UnpicklingError, OSError, IOError, EOFError): metadata = {} if baseurl not in metadata: metadata[baseurl]={} @@ -546,7 +546,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= sys.stderr.flush() mytempfile.close() try: - metadata[baseurl]["data"] = cPickle.loads(data) + metadata[baseurl]["data"] = pickle.loads(data) del data metadata[baseurl]["indexname"] = mfile metadata[baseurl]["timestamp"] = int(time.time()) @@ -562,7 +562,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= sys.stderr.flush() try: metadatafile = open("/var/cache/edb/remote_metadata.pickle", "w+") - cPickle.dump(metadata,metadatafile) + pickle.dump(metadata,metadatafile) metadatafile.close() except SystemExit, e: raise @@ -652,11 +652,11 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= if "modified" in metadata[baseurl] and metadata[baseurl]["modified"]: metadata[baseurl]["timestamp"] = int(time.time()) metadatafile = open("/var/cache/edb/remote_metadata.pickle", "w+") - cPickle.dump(metadata,metadatafile) + pickle.dump(metadata,metadatafile) metadatafile.close() if makepickle: metadatafile = open(makepickle, "w") - cPickle.dump(metadata[baseurl]["data"],metadatafile) + pickle.dump(metadata[baseurl]["data"],metadatafile) metadatafile.close() except SystemExit, e: raise diff --git a/pym/portage/util.py b/pym/portage/util.py index 177a6db9c..0e4fd0bd3 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -17,9 +17,9 @@ import portage.exception from portage.dep import isvalidatom try: - import cPickle + import cPickle as pickle except ImportError: - import pickle as cPickle + import pickle try: import cStringIO as StringIO @@ -568,7 +568,7 @@ def pickle_write(data,filename,debug=0): import os try: myf=open(filename,"w") - cPickle.dump(data,myf,-1) + pickle.dump(data,myf,-1) myf.flush() myf.close() writemsg("Wrote pickle: "+str(filename)+"\n",1) @@ -588,7 +588,7 @@ def pickle_read(filename,default=None,debug=0): data = None try: myf = open(filename) - mypickle = cPickle.Unpickler(myf) + mypickle = pickle.Unpickler(myf) mypickle.find_global = None data = mypickle.load() myf.close()