Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Gentoo Portage Developer (http://www.linux-archive.org/gentoo-portage-developer/)
-   -   import cPickle as pickle (http://www.linux-archive.org/gentoo-portage-developer/164974-import-cpickle-pickle.html)

Ali Polatel 09-23-2008 06:11 PM

import cPickle as pickle
 
The attached patch makes how we import cPickle and pickle consistent.
Importing it like:
try:
import cPickle as pickle
except ImportError:
import pickle
eases 2to3's job because cPickle won't exist in py3k and 2to3 does s/cPickle/pickle.
This is a patch to reduce the size of 2to3 patches┬╣. :)

┬╣: http://dev.gentoo.org/~hawking/portage-2to3/status.xml

---
pym/_emerge/__init__.py | 14 +++++++-------
pym/portage/__init__.py | 12 ++++++------
pym/portage/dbapi/vartree.py | 16 ++++++++--------
pym/portage/getbinpkg.py | 16 ++++++++--------
pym/portage/util.py | 8 ++++----
5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index 6b1ac46..ece3bae 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
" %
(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)
@@ -12923,7 +12923,7 @@ def action_build(settings, trees, mtimedb,
# sets unpickler.find_global = None which causes unpickler.load()
# to raise the following exception:
#
- # cPickle.UnpicklingError: Global and instance pickles are not supported.
+ # pickle.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.
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 79d99f8..4e88931 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
" %
(filename, str(e)), noiselevel=-1)
del e
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 56e0840..f5c0e2b 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
" %
(self._aux_cache_filename, str(e)), noiselevel=-1)
del e
diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py
index da0dd77..cd1bd0d 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.
")
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 177a6db..0e4fd0b 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)+"
",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()
--
Regards,
Ali Polatel

Zac Medico 09-23-2008 08:04 PM

import cPickle as pickle
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ali Polatel wrote:
> The attached patch makes how we import cPickle and pickle consistent.
> Importing it like:
> try:
> import cPickle as pickle
> except ImportError:
> import pickle
> eases 2to3's job because cPickle won't exist in py3k and 2to3 does s/cPickle/pickle.
> This is a patch to reduce the size of 2to3 patches╣. :)

Thanks, applied.
- --
Thanks,
Zac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkjZS9EACgkQ/ejvha5XGaORJACg2KuCHvlq3IEBAbYSc6echcbe
z3EAn3DDLdL0l0pD3nE7TuSM3QIJuoO8
=rkLS
-----END PGP SIGNATURE-----


All times are GMT. The time now is 11:26 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.