1 |
The attached patch makes how we import cPickle and pickle consistent. |
2 |
Importing it like: |
3 |
try: |
4 |
import cPickle as pickle |
5 |
except ImportError: |
6 |
import pickle |
7 |
eases 2to3's job because cPickle won't exist in py3k and 2to3 does s/cPickle/pickle. |
8 |
This is a patch to reduce the size of 2to3 patches¹. :) |
9 |
|
10 |
¹: http://dev.gentoo.org/~hawking/portage-2to3/status.xml |
11 |
|
12 |
--- |
13 |
pym/_emerge/__init__.py | 14 +++++++------- |
14 |
pym/portage/__init__.py | 12 ++++++------ |
15 |
pym/portage/dbapi/vartree.py | 16 ++++++++-------- |
16 |
pym/portage/getbinpkg.py | 16 ++++++++-------- |
17 |
pym/portage/util.py | 8 ++++---- |
18 |
5 files changed, 33 insertions(+), 33 deletions(-) |
19 |
|
20 |
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py |
21 |
index 6b1ac46..ece3bae 100644 |
22 |
--- a/pym/_emerge/__init__.py |
23 |
+++ b/pym/_emerge/__init__.py |
24 |
@@ -73,9 +73,9 @@ from itertools import chain, izip |
25 |
from UserDict import DictMixin |
26 |
|
27 |
try: |
28 |
- import cPickle |
29 |
+ import cPickle as pickle |
30 |
except ImportError: |
31 |
- import pickle as cPickle |
32 |
+ import pickle |
33 |
|
34 |
try: |
35 |
import cStringIO as StringIO |
36 |
@@ -3659,13 +3659,13 @@ class BlockerCache(DictMixin): |
37 |
def _load(self): |
38 |
try: |
39 |
f = open(self._cache_filename) |
40 |
- mypickle = cPickle.Unpickler(f) |
41 |
+ mypickle = pickle.Unpickler(f) |
42 |
mypickle.find_global = None |
43 |
self._cache_data = mypickle.load() |
44 |
f.close() |
45 |
del f |
46 |
- except (IOError, OSError, EOFError, cPickle.UnpicklingError), e: |
47 |
- if isinstance(e, cPickle.UnpicklingError): |
48 |
+ except (IOError, OSError, EOFError, pickle.UnpicklingError), e: |
49 |
+ if isinstance(e, pickle.UnpicklingError): |
50 |
writemsg("!!! Error loading '%s': %s\n" % \ |
51 |
(self._cache_filename, str(e)), noiselevel=-1) |
52 |
del e |
53 |
@@ -3745,7 +3745,7 @@ class BlockerCache(DictMixin): |
54 |
secpass >= 2: |
55 |
try: |
56 |
f = portage.util.atomic_ofstream(self._cache_filename) |
57 |
- cPickle.dump(self._cache_data, f, -1) |
58 |
+ pickle.dump(self._cache_data, f, -1) |
59 |
f.close() |
60 |
portage.util.apply_secpass_permissions( |
61 |
self._cache_filename, gid=portage.portage_gid, mode=0644) |
62 |
@@ -12923,7 +12923,7 @@ def action_build(settings, trees, mtimedb, |
63 |
# sets unpickler.find_global = None which causes unpickler.load() |
64 |
# to raise the following exception: |
65 |
# |
66 |
- # cPickle.UnpicklingError: Global and instance pickles are not supported. |
67 |
+ # pickle.UnpicklingError: Global and instance pickles are not supported. |
68 |
# |
69 |
# TODO: Maybe stop setting find_global = None, or find some other |
70 |
# way to avoid accidental triggering of the above UnpicklingError. |
71 |
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py |
72 |
index 79d99f8..4e88931 100644 |
73 |
--- a/pym/portage/__init__.py |
74 |
+++ b/pym/portage/__init__.py |
75 |
@@ -20,9 +20,9 @@ try: |
76 |
import shutil |
77 |
import time |
78 |
try: |
79 |
- import cPickle |
80 |
+ import cPickle as pickle |
81 |
except ImportError: |
82 |
- import pickle as cPickle |
83 |
+ import pickle |
84 |
|
85 |
import stat |
86 |
import commands |
87 |
@@ -7025,7 +7025,7 @@ def commit_mtimedb(mydict=None, filename=None): |
88 |
d.update(mydict) |
89 |
try: |
90 |
f = atomic_ofstream(filename) |
91 |
- cPickle.dump(d, f, -1) |
92 |
+ pickle.dump(d, f, -1) |
93 |
f.close() |
94 |
portage.util.apply_secpass_permissions(filename, uid=uid, gid=portage_gid, mode=0664) |
95 |
except (IOError, OSError), e: |
96 |
@@ -7179,13 +7179,13 @@ class MtimeDB(dict): |
97 |
def _load(self, filename): |
98 |
try: |
99 |
f = open(filename) |
100 |
- mypickle = cPickle.Unpickler(f) |
101 |
+ mypickle = pickle.Unpickler(f) |
102 |
mypickle.find_global = None |
103 |
d = mypickle.load() |
104 |
f.close() |
105 |
del f |
106 |
- except (IOError, OSError, EOFError, cPickle.UnpicklingError), e: |
107 |
- if isinstance(e, cPickle.UnpicklingError): |
108 |
+ except (IOError, OSError, EOFError, pickle.UnpicklingError), e: |
109 |
+ if isinstance(e, pickle.UnpicklingError): |
110 |
writemsg("!!! Error loading '%s': %s\n" % \ |
111 |
(filename, str(e)), noiselevel=-1) |
112 |
del e |
113 |
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py |
114 |
index 56e0840..f5c0e2b 100644 |
115 |
--- a/pym/portage/dbapi/vartree.py |
116 |
+++ b/pym/portage/dbapi/vartree.py |
117 |
@@ -37,9 +37,9 @@ import shlex |
118 |
from itertools import izip |
119 |
|
120 |
try: |
121 |
- import cPickle |
122 |
+ import cPickle as pickle |
123 |
except ImportError: |
124 |
- import pickle as cPickle |
125 |
+ import pickle |
126 |
|
127 |
class PreservedLibsRegistry(object): |
128 |
""" This class handles the tracking of preserved library objects """ |
129 |
@@ -57,7 +57,7 @@ class PreservedLibsRegistry(object): |
130 |
def load(self): |
131 |
""" Reload the registry data from file """ |
132 |
try: |
133 |
- self._data = cPickle.load(open(self._filename, "r")) |
134 |
+ self._data = pickle.load(open(self._filename, "r")) |
135 |
except (EOFError, IOError), e: |
136 |
if isinstance(e, EOFError) or e.errno == errno.ENOENT: |
137 |
self._data = {} |
138 |
@@ -74,7 +74,7 @@ class PreservedLibsRegistry(object): |
139 |
return |
140 |
try: |
141 |
f = atomic_ofstream(self._filename) |
142 |
- cPickle.dump(self._data, f) |
143 |
+ pickle.dump(self._data, f) |
144 |
f.close() |
145 |
except EnvironmentError, e: |
146 |
if e.errno != PermissionDenied.errno: |
147 |
@@ -956,7 +956,7 @@ class vardbapi(dbapi): |
148 |
del self._aux_cache["modified"] |
149 |
try: |
150 |
f = atomic_ofstream(self._aux_cache_filename) |
151 |
- cPickle.dump(self._aux_cache, f, -1) |
152 |
+ pickle.dump(self._aux_cache, f, -1) |
153 |
f.close() |
154 |
apply_secpass_permissions( |
155 |
self._aux_cache_filename, gid=portage_gid, mode=0644) |
156 |
@@ -974,13 +974,13 @@ class vardbapi(dbapi): |
157 |
aux_cache = None |
158 |
try: |
159 |
f = open(self._aux_cache_filename) |
160 |
- mypickle = cPickle.Unpickler(f) |
161 |
+ mypickle = pickle.Unpickler(f) |
162 |
mypickle.find_global = None |
163 |
aux_cache = mypickle.load() |
164 |
f.close() |
165 |
del f |
166 |
- except (IOError, OSError, EOFError, cPickle.UnpicklingError), e: |
167 |
- if isinstance(e, cPickle.UnpicklingError): |
168 |
+ except (IOError, OSError, EOFError, pickle.UnpicklingError), e: |
169 |
+ if isinstance(e, pickle.UnpicklingError): |
170 |
writemsg("!!! Error loading '%s': %s\n" % \ |
171 |
(self._aux_cache_filename, str(e)), noiselevel=-1) |
172 |
del e |
173 |
diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py |
174 |
index da0dd77..cd1bd0d 100644 |
175 |
--- a/pym/portage/getbinpkg.py |
176 |
+++ b/pym/portage/getbinpkg.py |
177 |
@@ -15,9 +15,9 @@ import base64 |
178 |
import urllib2 |
179 |
|
180 |
try: |
181 |
- import cPickle |
182 |
+ import cPickle as pickle |
183 |
except ImportError: |
184 |
- import pickle as cPickle |
185 |
+ import pickle |
186 |
|
187 |
try: |
188 |
import ftplib |
189 |
@@ -473,11 +473,11 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= |
190 |
out = sys.stdout |
191 |
try: |
192 |
metadatafile = open("/var/cache/edb/remote_metadata.pickle") |
193 |
- metadata = cPickle.load(metadatafile) |
194 |
+ metadata = pickle.load(metadatafile) |
195 |
out.write("Loaded metadata pickle.\n") |
196 |
out.flush() |
197 |
metadatafile.close() |
198 |
- except (cPickle.UnpicklingError, OSError, IOError, EOFError): |
199 |
+ except (pickle.UnpicklingError, OSError, IOError, EOFError): |
200 |
metadata = {} |
201 |
if baseurl not in metadata: |
202 |
metadata[baseurl]={} |
203 |
@@ -546,7 +546,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= |
204 |
sys.stderr.flush() |
205 |
mytempfile.close() |
206 |
try: |
207 |
- metadata[baseurl]["data"] = cPickle.loads(data) |
208 |
+ metadata[baseurl]["data"] = pickle.loads(data) |
209 |
del data |
210 |
metadata[baseurl]["indexname"] = mfile |
211 |
metadata[baseurl]["timestamp"] = int(time.time()) |
212 |
@@ -562,7 +562,7 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= |
213 |
sys.stderr.flush() |
214 |
try: |
215 |
metadatafile = open("/var/cache/edb/remote_metadata.pickle", "w+") |
216 |
- cPickle.dump(metadata,metadatafile) |
217 |
+ pickle.dump(metadata,metadatafile) |
218 |
metadatafile.close() |
219 |
except SystemExit, e: |
220 |
raise |
221 |
@@ -652,11 +652,11 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= |
222 |
if "modified" in metadata[baseurl] and metadata[baseurl]["modified"]: |
223 |
metadata[baseurl]["timestamp"] = int(time.time()) |
224 |
metadatafile = open("/var/cache/edb/remote_metadata.pickle", "w+") |
225 |
- cPickle.dump(metadata,metadatafile) |
226 |
+ pickle.dump(metadata,metadatafile) |
227 |
metadatafile.close() |
228 |
if makepickle: |
229 |
metadatafile = open(makepickle, "w") |
230 |
- cPickle.dump(metadata[baseurl]["data"],metadatafile) |
231 |
+ pickle.dump(metadata[baseurl]["data"],metadatafile) |
232 |
metadatafile.close() |
233 |
except SystemExit, e: |
234 |
raise |
235 |
diff --git a/pym/portage/util.py b/pym/portage/util.py |
236 |
index 177a6db..0e4fd0b 100644 |
237 |
--- a/pym/portage/util.py |
238 |
+++ b/pym/portage/util.py |
239 |
@@ -17,9 +17,9 @@ import portage.exception |
240 |
from portage.dep import isvalidatom |
241 |
|
242 |
try: |
243 |
- import cPickle |
244 |
+ import cPickle as pickle |
245 |
except ImportError: |
246 |
- import pickle as cPickle |
247 |
+ import pickle |
248 |
|
249 |
try: |
250 |
import cStringIO as StringIO |
251 |
@@ -568,7 +568,7 @@ def pickle_write(data,filename,debug=0): |
252 |
import os |
253 |
try: |
254 |
myf=open(filename,"w") |
255 |
- cPickle.dump(data,myf,-1) |
256 |
+ pickle.dump(data,myf,-1) |
257 |
myf.flush() |
258 |
myf.close() |
259 |
writemsg("Wrote pickle: "+str(filename)+"\n",1) |
260 |
@@ -588,7 +588,7 @@ def pickle_read(filename,default=None,debug=0): |
261 |
data = None |
262 |
try: |
263 |
myf = open(filename) |
264 |
- mypickle = cPickle.Unpickler(myf) |
265 |
+ mypickle = pickle.Unpickler(myf) |
266 |
mypickle.find_global = None |
267 |
data = mypickle.load() |
268 |
myf.close() |
269 |
-- |
270 |
Regards, |
271 |
Ali Polatel |