Import cPickle as pickle instead of vice versa. Eases 2to3's job because
authorZac Medico <zmedico@gentoo.org>
Tue, 23 Sep 2008 20:04:09 +0000 (20:04 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 23 Sep 2008 20:04:09 +0000 (20:04 -0000)
cPickle won't exist in py3k and 2to3 does s/cPickle/pickle. Thanks to
Ali Polatel <hawking@g.o> for this patch.

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

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

index 6b1ac46d2fb8ec9fb98b0319825e64819b08c760..8122b0839d8a1d9ae1568e527c7f377a70b7b617 100644 (file)
@@ -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)
index 79d99f813eabc00730e232f331e305648aa5f1d7..4e88931d7c3804aa0e80787617ea8085c20f813a 100644 (file)
@@ -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
index 56e08402825f4a0ce65f27c0e55b0acd58b51692..f5c0e2b170b0cbb240d1b0dee11267d71f9f0dc8 100644 (file)
@@ -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
index da0dd77ad3e85ea6389befc9a12ee477d4f2348b..cd1bd0dc1d7ff9658ee986c39d68c3d41384a4ed 100644 (file)
@@ -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
index 177a6db9c0b92f5c5465c1ea7b317565b317a7d6..0e4fd0bd35a7f64d8877bf275709df2cd6732052 100644 (file)
@@ -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()