mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Rename copy_reg module to copyreg.
Updated documentation. Merged revisions 63042 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63042 | alexandre.vassalotti | 2008-05-11 04:25:28 -0400 (Sun, 11 May 2008) | 5 lines Added module stub for copy_reg renaming in 3.0. Renamed copy_reg to copyreg in the standard library, to avoid spurious warnings and ease later merging to py3k branch. Public documentation remains intact. ........
This commit is contained in:
parent
7760008c38
commit
f7fa63dd55
20 changed files with 309 additions and 307 deletions
|
@ -60,7 +60,7 @@ of lists by assigning a slice of the entire list, for example,
|
||||||
|
|
||||||
Classes can use the same interfaces to control copying that they use to control
|
Classes can use the same interfaces to control copying that they use to control
|
||||||
pickling. See the description of module :mod:`pickle` for information on these
|
pickling. See the description of module :mod:`pickle` for information on these
|
||||||
methods. The :mod:`copy` module does not use the :mod:`copy_reg` registration
|
methods. The :mod:`copy` module does not use the :mod:`copyreg` registration
|
||||||
module.
|
module.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
:mod:`copy_reg` --- Register :mod:`pickle` support functions
|
:mod:`copyreg` --- Register :mod:`pickle` support functions
|
||||||
============================================================
|
============================================================
|
||||||
|
|
||||||
.. module:: copy_reg
|
.. module:: copyreg
|
||||||
:synopsis: Register pickle support functions.
|
:synopsis: Register pickle support functions.
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
module: cPickle
|
module: cPickle
|
||||||
module: copy
|
module: copy
|
||||||
|
|
||||||
The :mod:`copy_reg` module provides support for the :mod:`pickle` and
|
The :mod:`copyreg` module provides support for the :mod:`pickle` and
|
||||||
:mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
|
:mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
|
||||||
future as well. It provides configuration information about object constructors
|
future as well. It provides configuration information about object constructors
|
||||||
which are not classes. Such constructors may be factory functions or class
|
which are not classes. Such constructors may be factory functions or class
|
|
@ -95,7 +95,7 @@ Sample output (may vary depending on the architecture)::
|
||||||
|
|
||||||
Loaded modules:
|
Loaded modules:
|
||||||
_types:
|
_types:
|
||||||
copy_reg: _inverted_registry,_slotnames,__all__
|
copyreg: _inverted_registry,_slotnames,__all__
|
||||||
sre_compile: isstring,_sre,_optimize_unicode
|
sre_compile: isstring,_sre,_optimize_unicode
|
||||||
_sre:
|
_sre:
|
||||||
sre_constants: REPEAT_ONE,makedict,AT_END_LINE
|
sre_constants: REPEAT_ONE,makedict,AT_END_LINE
|
||||||
|
|
|
@ -19,7 +19,7 @@ The list of modules described in this chapter is:
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
|
||||||
pickle.rst
|
pickle.rst
|
||||||
copy_reg.rst
|
copyreg.rst
|
||||||
shelve.rst
|
shelve.rst
|
||||||
marshal.rst
|
marshal.rst
|
||||||
anydbm.rst
|
anydbm.rst
|
||||||
|
|
|
@ -524,7 +524,7 @@ not :meth:`__reduce_ex__`, the :meth:`__reduce_ex__` implementation detects this
|
||||||
and calls :meth:`__reduce__`.
|
and calls :meth:`__reduce__`.
|
||||||
|
|
||||||
An alternative to implementing a :meth:`__reduce__` method on the object to be
|
An alternative to implementing a :meth:`__reduce__` method on the object to be
|
||||||
pickled, is to register the callable with the :mod:`copy_reg` module. This
|
pickled, is to register the callable with the :mod:`copyreg` module. This
|
||||||
module provides a way for programs to register "reduction functions" and
|
module provides a way for programs to register "reduction functions" and
|
||||||
constructors for user-defined types. Reduction functions have the same
|
constructors for user-defined types. Reduction functions have the same
|
||||||
semantics and interface as the :meth:`__reduce__` method described above, except
|
semantics and interface as the :meth:`__reduce__` method described above, except
|
||||||
|
@ -775,7 +775,7 @@ the same process or a new process. ::
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
Module :mod:`copy_reg`
|
Module :mod:`copyreg`
|
||||||
Pickle interface constructor registration for extension types.
|
Pickle interface constructor registration for extension types.
|
||||||
|
|
||||||
Module :mod:`shelve`
|
Module :mod:`shelve`
|
||||||
|
|
|
@ -49,7 +49,7 @@ __getstate__() and __setstate__(). See the documentation for module
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import types
|
import types
|
||||||
from copy_reg import dispatch_table
|
from copyreg import dispatch_table
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -37,7 +37,7 @@ import pickle
|
||||||
import threading
|
import threading
|
||||||
import Queue
|
import Queue
|
||||||
import traceback
|
import traceback
|
||||||
import copy_reg
|
import copyreg
|
||||||
import types
|
import types
|
||||||
import marshal
|
import marshal
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ def pickle_code(co):
|
||||||
# assert isinstance(fn, type.FunctionType)
|
# assert isinstance(fn, type.FunctionType)
|
||||||
# return repr(fn)
|
# return repr(fn)
|
||||||
|
|
||||||
copy_reg.pickle(types.CodeType, pickle_code, unpickle_code)
|
copyreg.pickle(types.CodeType, pickle_code, unpickle_code)
|
||||||
# copy_reg.pickle(types.FunctionType, pickle_function, unpickle_function)
|
# copyreg.pickle(types.FunctionType, pickle_function, unpickle_function)
|
||||||
|
|
||||||
BUFSIZE = 8*1024
|
BUFSIZE = 8*1024
|
||||||
LOCALHOST = '127.0.0.1'
|
LOCALHOST = '127.0.0.1'
|
||||||
|
|
|
@ -588,7 +588,7 @@ otherwise return -SIG, where SIG is the signal that killed it. """
|
||||||
|
|
||||||
__all__.extend(["spawnvp", "spawnvpe", "spawnlp", "spawnlpe",])
|
__all__.extend(["spawnvp", "spawnvpe", "spawnlp", "spawnlpe",])
|
||||||
|
|
||||||
import copy_reg as _copy_reg
|
import copyreg as _copyreg
|
||||||
|
|
||||||
def _make_stat_result(tup, dict):
|
def _make_stat_result(tup, dict):
|
||||||
return stat_result(tup, dict)
|
return stat_result(tup, dict)
|
||||||
|
@ -598,7 +598,7 @@ def _pickle_stat_result(sr):
|
||||||
return (_make_stat_result, args)
|
return (_make_stat_result, args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_copy_reg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
|
_copyreg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
|
||||||
except NameError: # stat_result may not exist
|
except NameError: # stat_result may not exist
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ def _pickle_statvfs_result(sr):
|
||||||
return (_make_statvfs_result, args)
|
return (_make_statvfs_result, args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_copy_reg.pickle(statvfs_result, _pickle_statvfs_result,
|
_copyreg.pickle(statvfs_result, _pickle_statvfs_result,
|
||||||
_make_statvfs_result)
|
_make_statvfs_result)
|
||||||
except NameError: # statvfs_result may not exist
|
except NameError: # statvfs_result may not exist
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Create portable serialized representations of Python objects.
|
"""Create portable serialized representations of Python objects.
|
||||||
|
|
||||||
See module copy_reg for a mechanism for registering custom picklers.
|
See module copyreg for a mechanism for registering custom picklers.
|
||||||
See module pickletools source for extensive comments.
|
See module pickletools source for extensive comments.
|
||||||
|
|
||||||
Classes:
|
Classes:
|
||||||
|
@ -26,8 +26,8 @@ Misc variables:
|
||||||
__version__ = "$Revision$" # Code version
|
__version__ = "$Revision$" # Code version
|
||||||
|
|
||||||
from types import FunctionType, BuiltinFunctionType
|
from types import FunctionType, BuiltinFunctionType
|
||||||
from copy_reg import dispatch_table
|
from copyreg import dispatch_table
|
||||||
from copy_reg import _extension_registry, _inverted_registry, _extension_cache
|
from copyreg import _extension_registry, _inverted_registry, _extension_cache
|
||||||
import marshal
|
import marshal
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
|
@ -299,7 +299,7 @@ class Pickler:
|
||||||
self.save_global(obj)
|
self.save_global(obj)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check copy_reg.dispatch_table
|
# Check copyreg.dispatch_table
|
||||||
reduce = dispatch_table.get(t)
|
reduce = dispatch_table.get(t)
|
||||||
if reduce:
|
if reduce:
|
||||||
rv = reduce(obj)
|
rv = reduce(obj)
|
||||||
|
|
|
@ -142,7 +142,7 @@ this and there isn't a use case that warrants the expense of such an
|
||||||
analysis.
|
analysis.
|
||||||
|
|
||||||
To this end, all tests for __safe_for_unpickling__ or for
|
To this end, all tests for __safe_for_unpickling__ or for
|
||||||
copy_reg.safe_constructors are removed from the unpickling code.
|
copyreg.safe_constructors are removed from the unpickling code.
|
||||||
References to these variables in the descriptions below are to be seen
|
References to these variables in the descriptions below are to be seen
|
||||||
as describing unpickling in Python 2.2 and before.
|
as describing unpickling in Python 2.2 and before.
|
||||||
"""
|
"""
|
||||||
|
@ -1559,7 +1559,7 @@ opcodes = [
|
||||||
BUILD opcode to apply __setstate__ to that argument.
|
BUILD opcode to apply __setstate__ to that argument.
|
||||||
|
|
||||||
If not isinstance(callable, type), REDUCE complains unless the
|
If not isinstance(callable, type), REDUCE complains unless the
|
||||||
callable has been registered with the copy_reg module's
|
callable has been registered with the copyreg module's
|
||||||
safe_constructors dict, or the callable has a magic
|
safe_constructors dict, or the callable has a magic
|
||||||
'__safe_for_unpickling__' attribute with a true value. I'm not sure
|
'__safe_for_unpickling__' attribute with a true value. I'm not sure
|
||||||
why it does this, but I've sure seen this complaint often enough when
|
why it does this, but I've sure seen this complaint often enough when
|
||||||
|
@ -2137,58 +2137,58 @@ highest protocol among opcodes = 0
|
||||||
0: ( MARK
|
0: ( MARK
|
||||||
1: l LIST (MARK at 0)
|
1: l LIST (MARK at 0)
|
||||||
2: p PUT 0
|
2: p PUT 0
|
||||||
5: c GLOBAL 'copy_reg _reconstructor'
|
5: c GLOBAL 'copyreg _reconstructor'
|
||||||
30: p PUT 1
|
29: p PUT 1
|
||||||
33: ( MARK
|
32: ( MARK
|
||||||
34: c GLOBAL 'pickletools _Example'
|
33: c GLOBAL 'pickletools _Example'
|
||||||
56: p PUT 2
|
55: p PUT 2
|
||||||
59: c GLOBAL 'builtins object'
|
58: c GLOBAL 'builtins object'
|
||||||
76: p PUT 3
|
75: p PUT 3
|
||||||
79: N NONE
|
78: N NONE
|
||||||
80: t TUPLE (MARK at 33)
|
79: t TUPLE (MARK at 32)
|
||||||
81: p PUT 4
|
80: p PUT 4
|
||||||
84: R REDUCE
|
83: R REDUCE
|
||||||
85: p PUT 5
|
84: p PUT 5
|
||||||
88: ( MARK
|
87: ( MARK
|
||||||
89: d DICT (MARK at 88)
|
88: d DICT (MARK at 87)
|
||||||
90: p PUT 6
|
89: p PUT 6
|
||||||
93: V UNICODE 'value'
|
92: V UNICODE 'value'
|
||||||
100: p PUT 7
|
99: p PUT 7
|
||||||
103: L LONG 42
|
102: L LONG 42
|
||||||
107: s SETITEM
|
106: s SETITEM
|
||||||
108: b BUILD
|
107: b BUILD
|
||||||
109: a APPEND
|
108: a APPEND
|
||||||
110: g GET 5
|
109: g GET 5
|
||||||
113: a APPEND
|
112: a APPEND
|
||||||
114: . STOP
|
113: . STOP
|
||||||
highest protocol among opcodes = 0
|
highest protocol among opcodes = 0
|
||||||
|
|
||||||
>>> dis(pickle.dumps(x, 1))
|
>>> dis(pickle.dumps(x, 1))
|
||||||
0: ] EMPTY_LIST
|
0: ] EMPTY_LIST
|
||||||
1: q BINPUT 0
|
1: q BINPUT 0
|
||||||
3: ( MARK
|
3: ( MARK
|
||||||
4: c GLOBAL 'copy_reg _reconstructor'
|
4: c GLOBAL 'copyreg _reconstructor'
|
||||||
29: q BINPUT 1
|
28: q BINPUT 1
|
||||||
31: ( MARK
|
30: ( MARK
|
||||||
32: c GLOBAL 'pickletools _Example'
|
31: c GLOBAL 'pickletools _Example'
|
||||||
54: q BINPUT 2
|
53: q BINPUT 2
|
||||||
56: c GLOBAL 'builtins object'
|
55: c GLOBAL 'builtins object'
|
||||||
73: q BINPUT 3
|
72: q BINPUT 3
|
||||||
75: N NONE
|
74: N NONE
|
||||||
76: t TUPLE (MARK at 31)
|
75: t TUPLE (MARK at 30)
|
||||||
77: q BINPUT 4
|
76: q BINPUT 4
|
||||||
79: R REDUCE
|
78: R REDUCE
|
||||||
80: q BINPUT 5
|
79: q BINPUT 5
|
||||||
82: } EMPTY_DICT
|
81: } EMPTY_DICT
|
||||||
83: q BINPUT 6
|
82: q BINPUT 6
|
||||||
85: X BINUNICODE 'value'
|
84: X BINUNICODE 'value'
|
||||||
95: q BINPUT 7
|
94: q BINPUT 7
|
||||||
97: K BININT1 42
|
96: K BININT1 42
|
||||||
99: s SETITEM
|
98: s SETITEM
|
||||||
100: b BUILD
|
99: b BUILD
|
||||||
101: h BINGET 5
|
100: h BINGET 5
|
||||||
103: e APPENDS (MARK at 3)
|
102: e APPENDS (MARK at 3)
|
||||||
104: . STOP
|
103: . STOP
|
||||||
highest protocol among opcodes = 1
|
highest protocol among opcodes = 1
|
||||||
|
|
||||||
Try "the canonical" recursive-object test.
|
Try "the canonical" recursive-object test.
|
||||||
|
|
|
@ -272,12 +272,12 @@ def _subx(pattern, template):
|
||||||
|
|
||||||
# register myself for pickling
|
# register myself for pickling
|
||||||
|
|
||||||
import copy_reg
|
import copyreg
|
||||||
|
|
||||||
def _pickle(p):
|
def _pickle(p):
|
||||||
return _compile, (p.pattern, p.flags)
|
return _compile, (p.pattern, p.flags)
|
||||||
|
|
||||||
copy_reg.pickle(_pattern_type, _pickle, _compile)
|
copyreg.pickle(_pattern_type, _pickle, _compile)
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# experimental stuff (see python-dev discussions for details)
|
# experimental stuff (see python-dev discussions for details)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import pickle
|
import pickle
|
||||||
import pickletools
|
import pickletools
|
||||||
import copy_reg
|
import copyreg
|
||||||
|
|
||||||
from test.test_support import TestFailed, TESTFN, run_with_locale
|
from test.test_support import TestFailed, TESTFN, run_with_locale
|
||||||
|
|
||||||
|
@ -43,21 +43,21 @@ class ExtensionSaver:
|
||||||
# there is one).
|
# there is one).
|
||||||
def __init__(self, code):
|
def __init__(self, code):
|
||||||
self.code = code
|
self.code = code
|
||||||
if code in copy_reg._inverted_registry:
|
if code in copyreg._inverted_registry:
|
||||||
self.pair = copy_reg._inverted_registry[code]
|
self.pair = copyreg._inverted_registry[code]
|
||||||
copy_reg.remove_extension(self.pair[0], self.pair[1], code)
|
copyreg.remove_extension(self.pair[0], self.pair[1], code)
|
||||||
else:
|
else:
|
||||||
self.pair = None
|
self.pair = None
|
||||||
|
|
||||||
# Restore previous registration for code.
|
# Restore previous registration for code.
|
||||||
def restore(self):
|
def restore(self):
|
||||||
code = self.code
|
code = self.code
|
||||||
curpair = copy_reg._inverted_registry.get(code)
|
curpair = copyreg._inverted_registry.get(code)
|
||||||
if curpair is not None:
|
if curpair is not None:
|
||||||
copy_reg.remove_extension(curpair[0], curpair[1], code)
|
copyreg.remove_extension(curpair[0], curpair[1], code)
|
||||||
pair = self.pair
|
pair = self.pair
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
copy_reg.add_extension(pair[0], pair[1], code)
|
copyreg.add_extension(pair[0], pair[1], code)
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
@ -98,7 +98,7 @@ DATA0 = (
|
||||||
b'L-65535\naL-65536\naL2'
|
b'L-65535\naL-65536\naL2'
|
||||||
b'147483647\naL-2147483'
|
b'147483647\naL-2147483'
|
||||||
b'647\naL-2147483648\na('
|
b'647\naL-2147483648\na('
|
||||||
b'Vabc\np4\ng4\nccopy_reg'
|
b'Vabc\np4\ng4\nccopyreg'
|
||||||
b'\n_reconstructor\np5\n('
|
b'\n_reconstructor\np5\n('
|
||||||
b'c__main__\nC\np6\ncbu'
|
b'c__main__\nC\np6\ncbu'
|
||||||
b'iltins\nobject\np7\nNt'
|
b'iltins\nobject\np7\nNt'
|
||||||
|
@ -119,74 +119,74 @@ DATA0_DIS = """\
|
||||||
13: F FLOAT 2.0
|
13: F FLOAT 2.0
|
||||||
18: a APPEND
|
18: a APPEND
|
||||||
19: c GLOBAL 'builtins complex'
|
19: c GLOBAL 'builtins complex'
|
||||||
40: p PUT 1
|
37: p PUT 1
|
||||||
43: ( MARK
|
40: ( MARK
|
||||||
44: F FLOAT 3.0
|
41: F FLOAT 3.0
|
||||||
49: F FLOAT 0.0
|
46: F FLOAT 0.0
|
||||||
54: t TUPLE (MARK at 43)
|
51: t TUPLE (MARK at 40)
|
||||||
55: p PUT 2
|
52: p PUT 2
|
||||||
58: R REDUCE
|
55: R REDUCE
|
||||||
59: p PUT 3
|
56: p PUT 3
|
||||||
62: a APPEND
|
59: a APPEND
|
||||||
63: L LONG 1
|
60: L LONG 1
|
||||||
66: a APPEND
|
63: a APPEND
|
||||||
67: L LONG -1
|
64: L LONG -1
|
||||||
71: a APPEND
|
68: a APPEND
|
||||||
72: L LONG 255
|
69: L LONG 255
|
||||||
77: a APPEND
|
74: a APPEND
|
||||||
78: L LONG -255
|
75: L LONG -255
|
||||||
84: a APPEND
|
81: a APPEND
|
||||||
85: L LONG -256
|
82: L LONG -256
|
||||||
91: a APPEND
|
88: a APPEND
|
||||||
92: L LONG 65535
|
89: L LONG 65535
|
||||||
99: a APPEND
|
96: a APPEND
|
||||||
100: L LONG -65535
|
97: L LONG -65535
|
||||||
108: a APPEND
|
105: a APPEND
|
||||||
109: L LONG -65536
|
106: L LONG -65536
|
||||||
117: a APPEND
|
114: a APPEND
|
||||||
118: L LONG 2147483647
|
115: L LONG 2147483647
|
||||||
130: a APPEND
|
127: a APPEND
|
||||||
131: L LONG -2147483647
|
128: L LONG -2147483647
|
||||||
144: a APPEND
|
141: a APPEND
|
||||||
145: L LONG -2147483648
|
142: L LONG -2147483648
|
||||||
158: a APPEND
|
155: a APPEND
|
||||||
159: ( MARK
|
156: ( MARK
|
||||||
160: V UNICODE 'abc'
|
157: V UNICODE 'abc'
|
||||||
165: p PUT 4
|
162: p PUT 4
|
||||||
168: g GET 4
|
165: g GET 4
|
||||||
171: c GLOBAL 'copy_reg _reconstructor'
|
168: c GLOBAL 'copyreg _reconstructor'
|
||||||
196: p PUT 5
|
192: p PUT 5
|
||||||
199: ( MARK
|
195: ( MARK
|
||||||
200: c GLOBAL '__main__ C'
|
196: c GLOBAL '__main__ C'
|
||||||
212: p PUT 6
|
208: p PUT 6
|
||||||
215: c GLOBAL 'builtins object'
|
211: c GLOBAL 'builtins object'
|
||||||
235: p PUT 7
|
228: p PUT 7
|
||||||
238: N NONE
|
231: N NONE
|
||||||
239: t TUPLE (MARK at 199)
|
232: t TUPLE (MARK at 195)
|
||||||
240: p PUT 8
|
233: p PUT 8
|
||||||
243: R REDUCE
|
236: R REDUCE
|
||||||
244: p PUT 9
|
237: p PUT 9
|
||||||
247: ( MARK
|
240: ( MARK
|
||||||
248: d DICT (MARK at 247)
|
241: d DICT (MARK at 240)
|
||||||
249: p PUT 10
|
242: p PUT 10
|
||||||
253: V UNICODE 'foo'
|
246: V UNICODE 'foo'
|
||||||
258: p PUT 11
|
251: p PUT 11
|
||||||
262: L LONG 1
|
255: L LONG 1
|
||||||
265: s SETITEM
|
258: s SETITEM
|
||||||
266: V UNICODE 'bar'
|
259: V UNICODE 'bar'
|
||||||
271: p PUT 12
|
264: p PUT 12
|
||||||
275: L LONG 2
|
268: L LONG 2
|
||||||
278: s SETITEM
|
271: s SETITEM
|
||||||
279: b BUILD
|
272: b BUILD
|
||||||
280: g GET 9
|
273: g GET 9
|
||||||
283: t TUPLE (MARK at 159)
|
276: t TUPLE (MARK at 156)
|
||||||
284: p PUT 13
|
277: p PUT 13
|
||||||
288: a APPEND
|
281: a APPEND
|
||||||
289: g GET 13
|
282: g GET 13
|
||||||
293: a APPEND
|
286: a APPEND
|
||||||
294: L LONG 5
|
287: L LONG 5
|
||||||
297: a APPEND
|
290: a APPEND
|
||||||
298: . STOP
|
291: . STOP
|
||||||
highest protocol among opcodes = 0
|
highest protocol among opcodes = 0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ DATA1 = (
|
||||||
b'q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xffJ'
|
b'q\x02Rq\x03K\x01J\xff\xff\xff\xffK\xffJ\x01\xff\xff\xffJ'
|
||||||
b'\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff\xff'
|
b'\x00\xff\xff\xffM\xff\xffJ\x01\x00\xff\xffJ\x00\x00\xff\xffJ\xff\xff'
|
||||||
b'\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00\x80(X\x03\x00\x00\x00ab'
|
b'\xff\x7fJ\x01\x00\x00\x80J\x00\x00\x00\x80(X\x03\x00\x00\x00ab'
|
||||||
b'cq\x04h\x04ccopy_reg\n_reco'
|
b'cq\x04h\x04ccopyreg\n_reco'
|
||||||
b'nstructor\nq\x05(c__main'
|
b'nstructor\nq\x05(c__main'
|
||||||
b'__\nC\nq\x06cbuiltins\n'
|
b'__\nC\nq\x06cbuiltins\n'
|
||||||
b'object\nq\x07Ntq\x08Rq\t}q\n('
|
b'object\nq\x07Ntq\x08Rq\t}q\n('
|
||||||
|
@ -214,59 +214,59 @@ DATA1_DIS = """\
|
||||||
6: K BININT1 1
|
6: K BININT1 1
|
||||||
8: G BINFLOAT 2.0
|
8: G BINFLOAT 2.0
|
||||||
17: c GLOBAL 'builtins complex'
|
17: c GLOBAL 'builtins complex'
|
||||||
38: q BINPUT 1
|
35: q BINPUT 1
|
||||||
40: ( MARK
|
37: ( MARK
|
||||||
41: G BINFLOAT 3.0
|
38: G BINFLOAT 3.0
|
||||||
50: G BINFLOAT 0.0
|
47: G BINFLOAT 0.0
|
||||||
59: t TUPLE (MARK at 40)
|
56: t TUPLE (MARK at 37)
|
||||||
60: q BINPUT 2
|
57: q BINPUT 2
|
||||||
62: R REDUCE
|
59: R REDUCE
|
||||||
63: q BINPUT 3
|
60: q BINPUT 3
|
||||||
65: K BININT1 1
|
62: K BININT1 1
|
||||||
67: J BININT -1
|
64: J BININT -1
|
||||||
72: K BININT1 255
|
69: K BININT1 255
|
||||||
74: J BININT -255
|
71: J BININT -255
|
||||||
79: J BININT -256
|
76: J BININT -256
|
||||||
84: M BININT2 65535
|
81: M BININT2 65535
|
||||||
87: J BININT -65535
|
84: J BININT -65535
|
||||||
92: J BININT -65536
|
89: J BININT -65536
|
||||||
97: J BININT 2147483647
|
94: J BININT 2147483647
|
||||||
102: J BININT -2147483647
|
99: J BININT -2147483647
|
||||||
107: J BININT -2147483648
|
104: J BININT -2147483648
|
||||||
112: ( MARK
|
109: ( MARK
|
||||||
113: X BINUNICODE 'abc'
|
110: X BINUNICODE 'abc'
|
||||||
121: q BINPUT 4
|
118: q BINPUT 4
|
||||||
123: h BINGET 4
|
120: h BINGET 4
|
||||||
125: c GLOBAL 'copy_reg _reconstructor'
|
122: c GLOBAL 'copyreg _reconstructor'
|
||||||
150: q BINPUT 5
|
146: q BINPUT 5
|
||||||
152: ( MARK
|
148: ( MARK
|
||||||
153: c GLOBAL '__main__ C'
|
149: c GLOBAL '__main__ C'
|
||||||
165: q BINPUT 6
|
161: q BINPUT 6
|
||||||
167: c GLOBAL 'builtins object'
|
163: c GLOBAL 'builtins object'
|
||||||
187: q BINPUT 7
|
180: q BINPUT 7
|
||||||
189: N NONE
|
182: N NONE
|
||||||
190: t TUPLE (MARK at 152)
|
183: t TUPLE (MARK at 148)
|
||||||
191: q BINPUT 8
|
184: q BINPUT 8
|
||||||
193: R REDUCE
|
186: R REDUCE
|
||||||
194: q BINPUT 9
|
187: q BINPUT 9
|
||||||
196: } EMPTY_DICT
|
189: } EMPTY_DICT
|
||||||
197: q BINPUT 10
|
190: q BINPUT 10
|
||||||
199: ( MARK
|
192: ( MARK
|
||||||
200: X BINUNICODE 'foo'
|
193: X BINUNICODE 'foo'
|
||||||
208: q BINPUT 11
|
201: q BINPUT 11
|
||||||
210: K BININT1 1
|
203: K BININT1 1
|
||||||
212: X BINUNICODE 'bar'
|
205: X BINUNICODE 'bar'
|
||||||
220: q BINPUT 12
|
213: q BINPUT 12
|
||||||
222: K BININT1 2
|
215: K BININT1 2
|
||||||
224: u SETITEMS (MARK at 199)
|
217: u SETITEMS (MARK at 192)
|
||||||
225: b BUILD
|
218: b BUILD
|
||||||
226: h BINGET 9
|
219: h BINGET 9
|
||||||
228: t TUPLE (MARK at 112)
|
221: t TUPLE (MARK at 109)
|
||||||
229: q BINPUT 13
|
222: q BINPUT 13
|
||||||
231: h BINGET 13
|
224: h BINGET 13
|
||||||
233: K BININT1 5
|
226: K BININT1 5
|
||||||
235: e APPENDS (MARK at 3)
|
228: e APPENDS (MARK at 3)
|
||||||
236: . STOP
|
229: . STOP
|
||||||
highest protocol among opcodes = 1
|
highest protocol among opcodes = 1
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -293,51 +293,51 @@ DATA2_DIS = """\
|
||||||
8: K BININT1 1
|
8: K BININT1 1
|
||||||
10: G BINFLOAT 2.0
|
10: G BINFLOAT 2.0
|
||||||
19: c GLOBAL 'builtins complex'
|
19: c GLOBAL 'builtins complex'
|
||||||
40: q BINPUT 1
|
37: q BINPUT 1
|
||||||
42: G BINFLOAT 3.0
|
39: G BINFLOAT 3.0
|
||||||
51: G BINFLOAT 0.0
|
48: G BINFLOAT 0.0
|
||||||
60: \x86 TUPLE2
|
57: \x86 TUPLE2
|
||||||
61: q BINPUT 2
|
58: q BINPUT 2
|
||||||
63: R REDUCE
|
60: R REDUCE
|
||||||
64: q BINPUT 3
|
61: q BINPUT 3
|
||||||
66: K BININT1 1
|
63: K BININT1 1
|
||||||
68: J BININT -1
|
65: J BININT -1
|
||||||
73: K BININT1 255
|
70: K BININT1 255
|
||||||
75: J BININT -255
|
72: J BININT -255
|
||||||
80: J BININT -256
|
77: J BININT -256
|
||||||
85: M BININT2 65535
|
82: M BININT2 65535
|
||||||
88: J BININT -65535
|
85: J BININT -65535
|
||||||
93: J BININT -65536
|
90: J BININT -65536
|
||||||
98: J BININT 2147483647
|
95: J BININT 2147483647
|
||||||
103: J BININT -2147483647
|
100: J BININT -2147483647
|
||||||
108: J BININT -2147483648
|
105: J BININT -2147483648
|
||||||
113: ( MARK
|
110: ( MARK
|
||||||
114: X BINUNICODE 'abc'
|
111: X BINUNICODE 'abc'
|
||||||
122: q BINPUT 4
|
119: q BINPUT 4
|
||||||
124: h BINGET 4
|
121: h BINGET 4
|
||||||
126: c GLOBAL '__main__ C'
|
123: c GLOBAL '__main__ C'
|
||||||
138: q BINPUT 5
|
135: q BINPUT 5
|
||||||
140: ) EMPTY_TUPLE
|
137: ) EMPTY_TUPLE
|
||||||
141: \x81 NEWOBJ
|
138: \x81 NEWOBJ
|
||||||
142: q BINPUT 6
|
139: q BINPUT 6
|
||||||
144: } EMPTY_DICT
|
141: } EMPTY_DICT
|
||||||
145: q BINPUT 7
|
142: q BINPUT 7
|
||||||
147: ( MARK
|
144: ( MARK
|
||||||
148: X BINUNICODE 'foo'
|
145: X BINUNICODE 'foo'
|
||||||
156: q BINPUT 8
|
153: q BINPUT 8
|
||||||
158: K BININT1 1
|
155: K BININT1 1
|
||||||
160: X BINUNICODE 'bar'
|
157: X BINUNICODE 'bar'
|
||||||
168: q BINPUT 9
|
165: q BINPUT 9
|
||||||
170: K BININT1 2
|
167: K BININT1 2
|
||||||
172: u SETITEMS (MARK at 147)
|
169: u SETITEMS (MARK at 144)
|
||||||
173: b BUILD
|
170: b BUILD
|
||||||
174: h BINGET 6
|
171: h BINGET 6
|
||||||
176: t TUPLE (MARK at 113)
|
173: t TUPLE (MARK at 110)
|
||||||
177: q BINPUT 10
|
174: q BINPUT 10
|
||||||
179: h BINGET 10
|
176: h BINGET 10
|
||||||
181: K BININT1 5
|
178: K BININT1 5
|
||||||
183: e APPENDS (MARK at 5)
|
180: e APPENDS (MARK at 5)
|
||||||
184: . STOP
|
181: . STOP
|
||||||
highest protocol among opcodes = 2
|
highest protocol among opcodes = 2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -707,14 +707,14 @@ class AbstractPickleTests(unittest.TestCase):
|
||||||
self.assertEqual(B(x), B(y), detail)
|
self.assertEqual(B(x), B(y), detail)
|
||||||
self.assertEqual(x.__dict__, y.__dict__, detail)
|
self.assertEqual(x.__dict__, y.__dict__, detail)
|
||||||
|
|
||||||
# Register a type with copy_reg, with extension code extcode. Pickle
|
# Register a type with copyreg, with extension code extcode. Pickle
|
||||||
# an object of that type. Check that the resulting pickle uses opcode
|
# an object of that type. Check that the resulting pickle uses opcode
|
||||||
# (EXT[124]) under proto 2, and not in proto 1.
|
# (EXT[124]) under proto 2, and not in proto 1.
|
||||||
|
|
||||||
def produce_global_ext(self, extcode, opcode):
|
def produce_global_ext(self, extcode, opcode):
|
||||||
e = ExtensionSaver(extcode)
|
e = ExtensionSaver(extcode)
|
||||||
try:
|
try:
|
||||||
copy_reg.add_extension(__name__, "MyList", extcode)
|
copyreg.add_extension(__name__, "MyList", extcode)
|
||||||
x = MyList([1, 2, 3])
|
x = MyList([1, 2, 3])
|
||||||
x.foo = 42
|
x.foo = 42
|
||||||
x.bar = "hello"
|
x.bar = "hello"
|
||||||
|
|
|
@ -676,7 +676,7 @@ def cleanup_test_droppings(testname, verbose):
|
||||||
|
|
||||||
def dash_R(the_module, test, indirect_test, huntrleaks):
|
def dash_R(the_module, test, indirect_test, huntrleaks):
|
||||||
# This code is hackish and inelegant, but it seems to do the job.
|
# This code is hackish and inelegant, but it seems to do the job.
|
||||||
import copy_reg, _abcoll
|
import copyreg, _abcoll
|
||||||
|
|
||||||
if not hasattr(sys, 'gettotalrefcount'):
|
if not hasattr(sys, 'gettotalrefcount'):
|
||||||
raise Exception("Tracking reference leaks requires a debug build "
|
raise Exception("Tracking reference leaks requires a debug build "
|
||||||
|
@ -684,7 +684,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
|
||||||
|
|
||||||
# Save current values for dash_R_cleanup() to restore.
|
# Save current values for dash_R_cleanup() to restore.
|
||||||
fs = warnings.filters[:]
|
fs = warnings.filters[:]
|
||||||
ps = copy_reg.dispatch_table.copy()
|
ps = copyreg.dispatch_table.copy()
|
||||||
pic = sys.path_importer_cache.copy()
|
pic = sys.path_importer_cache.copy()
|
||||||
abcs = {}
|
abcs = {}
|
||||||
for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]:
|
for abc in [getattr(_abcoll, a) for a in _abcoll.__all__]:
|
||||||
|
@ -724,7 +724,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
|
||||||
refrep.close()
|
refrep.close()
|
||||||
|
|
||||||
def dash_R_cleanup(fs, ps, pic, abcs):
|
def dash_R_cleanup(fs, ps, pic, abcs):
|
||||||
import gc, copy_reg
|
import gc, copyreg
|
||||||
import _strptime, linecache
|
import _strptime, linecache
|
||||||
import urlparse, urllib, urllib2, mimetypes, doctest
|
import urlparse, urllib, urllib2, mimetypes, doctest
|
||||||
import struct, filecmp, _abcoll
|
import struct, filecmp, _abcoll
|
||||||
|
@ -738,8 +738,8 @@ def dash_R_cleanup(fs, ps, pic, abcs):
|
||||||
|
|
||||||
# Restore some original values.
|
# Restore some original values.
|
||||||
warnings.filters[:] = fs
|
warnings.filters[:] = fs
|
||||||
copy_reg.dispatch_table.clear()
|
copyreg.dispatch_table.clear()
|
||||||
copy_reg.dispatch_table.update(ps)
|
copyreg.dispatch_table.update(ps)
|
||||||
sys.path_importer_cache.clear()
|
sys.path_importer_cache.clear()
|
||||||
sys.path_importer_cache.update(pic)
|
sys.path_importer_cache.update(pic)
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ class AllTest(unittest.TestCase):
|
||||||
self.check_all("commands")
|
self.check_all("commands")
|
||||||
self.check_all("compileall")
|
self.check_all("compileall")
|
||||||
self.check_all("copy")
|
self.check_all("copy")
|
||||||
self.check_all("copy_reg")
|
self.check_all("copyreg")
|
||||||
self.check_all("csv")
|
self.check_all("csv")
|
||||||
self.check_all("dbhash")
|
self.check_all("dbhash")
|
||||||
self.check_all("decimal")
|
self.check_all("decimal")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Unit tests for the copy module."""
|
"""Unit tests for the copy module."""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import copy_reg
|
import copyreg
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
@ -42,7 +42,7 @@ class TestCopy(unittest.TestCase):
|
||||||
return (C, (obj.foo,))
|
return (C, (obj.foo,))
|
||||||
x = C(42)
|
x = C(42)
|
||||||
self.assertRaises(TypeError, copy.copy, x)
|
self.assertRaises(TypeError, copy.copy, x)
|
||||||
copy_reg.pickle(C, pickle_C, C)
|
copyreg.pickle(C, pickle_C, C)
|
||||||
y = copy.copy(x)
|
y = copy.copy(x)
|
||||||
|
|
||||||
def test_copy_reduce_ex(self):
|
def test_copy_reduce_ex(self):
|
||||||
|
@ -215,7 +215,7 @@ class TestCopy(unittest.TestCase):
|
||||||
return (C, (obj.foo,))
|
return (C, (obj.foo,))
|
||||||
x = C(42)
|
x = C(42)
|
||||||
self.assertRaises(TypeError, copy.deepcopy, x)
|
self.assertRaises(TypeError, copy.deepcopy, x)
|
||||||
copy_reg.pickle(C, pickle_C, C)
|
copyreg.pickle(C, pickle_C, C)
|
||||||
y = copy.deepcopy(x)
|
y = copy.deepcopy(x)
|
||||||
|
|
||||||
def test_deepcopy_reduce_ex(self):
|
def test_deepcopy_reduce_ex(self):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import copy_reg
|
import copyreg
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
@ -27,15 +27,15 @@ class WithInherited(WithSingleString):
|
||||||
class CopyRegTestCase(unittest.TestCase):
|
class CopyRegTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_class(self):
|
def test_class(self):
|
||||||
self.assertRaises(TypeError, copy_reg.pickle,
|
self.assertRaises(TypeError, copyreg.pickle,
|
||||||
C, None, None)
|
C, None, None)
|
||||||
|
|
||||||
def test_noncallable_reduce(self):
|
def test_noncallable_reduce(self):
|
||||||
self.assertRaises(TypeError, copy_reg.pickle,
|
self.assertRaises(TypeError, copyreg.pickle,
|
||||||
type(1), "not a callable")
|
type(1), "not a callable")
|
||||||
|
|
||||||
def test_noncallable_constructor(self):
|
def test_noncallable_constructor(self):
|
||||||
self.assertRaises(TypeError, copy_reg.pickle,
|
self.assertRaises(TypeError, copyreg.pickle,
|
||||||
type(1), int, "not a callable")
|
type(1), int, "not a callable")
|
||||||
|
|
||||||
def test_bool(self):
|
def test_bool(self):
|
||||||
|
@ -47,42 +47,42 @@ class CopyRegTestCase(unittest.TestCase):
|
||||||
e = ExtensionSaver(code)
|
e = ExtensionSaver(code)
|
||||||
try:
|
try:
|
||||||
# Shouldn't be in registry now.
|
# Shouldn't be in registry now.
|
||||||
self.assertRaises(ValueError, copy_reg.remove_extension,
|
self.assertRaises(ValueError, copyreg.remove_extension,
|
||||||
mod, func, code)
|
mod, func, code)
|
||||||
copy_reg.add_extension(mod, func, code)
|
copyreg.add_extension(mod, func, code)
|
||||||
# Should be in the registry.
|
# Should be in the registry.
|
||||||
self.assert_(copy_reg._extension_registry[mod, func] == code)
|
self.assert_(copyreg._extension_registry[mod, func] == code)
|
||||||
self.assert_(copy_reg._inverted_registry[code] == (mod, func))
|
self.assert_(copyreg._inverted_registry[code] == (mod, func))
|
||||||
# Shouldn't be in the cache.
|
# Shouldn't be in the cache.
|
||||||
self.assert_(code not in copy_reg._extension_cache)
|
self.assert_(code not in copyreg._extension_cache)
|
||||||
# Redundant registration should be OK.
|
# Redundant registration should be OK.
|
||||||
copy_reg.add_extension(mod, func, code) # shouldn't blow up
|
copyreg.add_extension(mod, func, code) # shouldn't blow up
|
||||||
# Conflicting code.
|
# Conflicting code.
|
||||||
self.assertRaises(ValueError, copy_reg.add_extension,
|
self.assertRaises(ValueError, copyreg.add_extension,
|
||||||
mod, func, code + 1)
|
mod, func, code + 1)
|
||||||
self.assertRaises(ValueError, copy_reg.remove_extension,
|
self.assertRaises(ValueError, copyreg.remove_extension,
|
||||||
mod, func, code + 1)
|
mod, func, code + 1)
|
||||||
# Conflicting module name.
|
# Conflicting module name.
|
||||||
self.assertRaises(ValueError, copy_reg.add_extension,
|
self.assertRaises(ValueError, copyreg.add_extension,
|
||||||
mod[1:], func, code )
|
mod[1:], func, code )
|
||||||
self.assertRaises(ValueError, copy_reg.remove_extension,
|
self.assertRaises(ValueError, copyreg.remove_extension,
|
||||||
mod[1:], func, code )
|
mod[1:], func, code )
|
||||||
# Conflicting function name.
|
# Conflicting function name.
|
||||||
self.assertRaises(ValueError, copy_reg.add_extension,
|
self.assertRaises(ValueError, copyreg.add_extension,
|
||||||
mod, func[1:], code)
|
mod, func[1:], code)
|
||||||
self.assertRaises(ValueError, copy_reg.remove_extension,
|
self.assertRaises(ValueError, copyreg.remove_extension,
|
||||||
mod, func[1:], code)
|
mod, func[1:], code)
|
||||||
# Can't remove one that isn't registered at all.
|
# Can't remove one that isn't registered at all.
|
||||||
if code + 1 not in copy_reg._inverted_registry:
|
if code + 1 not in copyreg._inverted_registry:
|
||||||
self.assertRaises(ValueError, copy_reg.remove_extension,
|
self.assertRaises(ValueError, copyreg.remove_extension,
|
||||||
mod[1:], func[1:], code + 1)
|
mod[1:], func[1:], code + 1)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
e.restore()
|
e.restore()
|
||||||
|
|
||||||
# Shouldn't be there anymore.
|
# Shouldn't be there anymore.
|
||||||
self.assert_((mod, func) not in copy_reg._extension_registry)
|
self.assert_((mod, func) not in copyreg._extension_registry)
|
||||||
# The code *may* be in copy_reg._extension_registry, though, if
|
# The code *may* be in copyreg._extension_registry, though, if
|
||||||
# we happened to pick on a registered code. So don't check for
|
# we happened to pick on a registered code. So don't check for
|
||||||
# that.
|
# that.
|
||||||
|
|
||||||
|
@ -90,25 +90,25 @@ class CopyRegTestCase(unittest.TestCase):
|
||||||
for code in 1, 0x7fffffff:
|
for code in 1, 0x7fffffff:
|
||||||
e = ExtensionSaver(code)
|
e = ExtensionSaver(code)
|
||||||
try:
|
try:
|
||||||
copy_reg.add_extension(mod, func, code)
|
copyreg.add_extension(mod, func, code)
|
||||||
copy_reg.remove_extension(mod, func, code)
|
copyreg.remove_extension(mod, func, code)
|
||||||
finally:
|
finally:
|
||||||
e.restore()
|
e.restore()
|
||||||
|
|
||||||
# Ensure invalid codes blow up.
|
# Ensure invalid codes blow up.
|
||||||
for code in -1, 0, 0x80000000:
|
for code in -1, 0, 0x80000000:
|
||||||
self.assertRaises(ValueError, copy_reg.add_extension,
|
self.assertRaises(ValueError, copyreg.add_extension,
|
||||||
mod, func, code)
|
mod, func, code)
|
||||||
|
|
||||||
def test_slotnames(self):
|
def test_slotnames(self):
|
||||||
self.assertEquals(copy_reg._slotnames(WithoutSlots), [])
|
self.assertEquals(copyreg._slotnames(WithoutSlots), [])
|
||||||
self.assertEquals(copy_reg._slotnames(WithWeakref), [])
|
self.assertEquals(copyreg._slotnames(WithWeakref), [])
|
||||||
expected = ['_WithPrivate__spam']
|
expected = ['_WithPrivate__spam']
|
||||||
self.assertEquals(copy_reg._slotnames(WithPrivate), expected)
|
self.assertEquals(copyreg._slotnames(WithPrivate), expected)
|
||||||
self.assertEquals(copy_reg._slotnames(WithSingleString), ['spam'])
|
self.assertEquals(copyreg._slotnames(WithSingleString), ['spam'])
|
||||||
expected = ['eggs', 'spam']
|
expected = ['eggs', 'spam']
|
||||||
expected.sort()
|
expected.sort()
|
||||||
result = copy_reg._slotnames(WithInherited)
|
result = copyreg._slotnames(WithInherited)
|
||||||
result.sort()
|
result.sort()
|
||||||
self.assertEquals(result, expected)
|
self.assertEquals(result, expected)
|
||||||
|
|
|
@ -21,6 +21,8 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- The copy_reg module has been renamed to copyreg.
|
||||||
|
|
||||||
- The mhlib module has been removed.
|
- The mhlib module has been removed.
|
||||||
|
|
||||||
- The ihooks module has been removed.
|
- The ihooks module has been removed.
|
||||||
|
|
|
@ -3091,7 +3091,7 @@ initparser(void)
|
||||||
* If this fails, the import of this module will fail because an
|
* If this fails, the import of this module will fail because an
|
||||||
* exception will be raised here; should we clear the exception?
|
* exception will be raised here; should we clear the exception?
|
||||||
*/
|
*/
|
||||||
copyreg = PyImport_ImportModuleNoBlock("copy_reg");
|
copyreg = PyImport_ImportModuleNoBlock("copyreg");
|
||||||
if (copyreg != NULL) {
|
if (copyreg != NULL) {
|
||||||
PyObject *func, *pickler;
|
PyObject *func, *pickler;
|
||||||
|
|
||||||
|
|
|
@ -2941,31 +2941,31 @@ static PyGetSetDef object_getsets[] = {
|
||||||
|
|
||||||
|
|
||||||
/* Stuff to implement __reduce_ex__ for pickle protocols >= 2.
|
/* Stuff to implement __reduce_ex__ for pickle protocols >= 2.
|
||||||
We fall back to helpers in copy_reg for:
|
We fall back to helpers in copyreg for:
|
||||||
- pickle protocols < 2
|
- pickle protocols < 2
|
||||||
- calculating the list of slot names (done only once per class)
|
- calculating the list of slot names (done only once per class)
|
||||||
- the __newobj__ function (which is used as a token but never called)
|
- the __newobj__ function (which is used as a token but never called)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
import_copy_reg(void)
|
import_copyreg(void)
|
||||||
{
|
{
|
||||||
static PyObject *copy_reg_str;
|
static PyObject *copyreg_str;
|
||||||
|
|
||||||
if (!copy_reg_str) {
|
if (!copyreg_str) {
|
||||||
copy_reg_str = PyUnicode_InternFromString("copy_reg");
|
copyreg_str = PyUnicode_InternFromString("copyreg");
|
||||||
if (copy_reg_str == NULL)
|
if (copyreg_str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PyImport_Import(copy_reg_str);
|
return PyImport_Import(copyreg_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
slotnames(PyObject *cls)
|
slotnames(PyObject *cls)
|
||||||
{
|
{
|
||||||
PyObject *clsdict;
|
PyObject *clsdict;
|
||||||
PyObject *copy_reg;
|
PyObject *copyreg;
|
||||||
PyObject *slotnames;
|
PyObject *slotnames;
|
||||||
|
|
||||||
if (!PyType_Check(cls)) {
|
if (!PyType_Check(cls)) {
|
||||||
|
@ -2980,18 +2980,18 @@ slotnames(PyObject *cls)
|
||||||
return slotnames;
|
return slotnames;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_reg = import_copy_reg();
|
copyreg = import_copyreg();
|
||||||
if (copy_reg == NULL)
|
if (copyreg == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
slotnames = PyObject_CallMethod(copy_reg, "_slotnames", "O", cls);
|
slotnames = PyObject_CallMethod(copyreg, "_slotnames", "O", cls);
|
||||||
Py_DECREF(copy_reg);
|
Py_DECREF(copyreg);
|
||||||
if (slotnames != NULL &&
|
if (slotnames != NULL &&
|
||||||
slotnames != Py_None &&
|
slotnames != Py_None &&
|
||||||
!PyList_Check(slotnames))
|
!PyList_Check(slotnames))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"copy_reg._slotnames didn't return a list or None");
|
"copyreg._slotnames didn't return a list or None");
|
||||||
Py_DECREF(slotnames);
|
Py_DECREF(slotnames);
|
||||||
slotnames = NULL;
|
slotnames = NULL;
|
||||||
}
|
}
|
||||||
|
@ -3006,7 +3006,7 @@ reduce_2(PyObject *obj)
|
||||||
PyObject *args = NULL, *args2 = NULL;
|
PyObject *args = NULL, *args2 = NULL;
|
||||||
PyObject *getstate = NULL, *state = NULL, *names = NULL;
|
PyObject *getstate = NULL, *state = NULL, *names = NULL;
|
||||||
PyObject *slots = NULL, *listitems = NULL, *dictitems = NULL;
|
PyObject *slots = NULL, *listitems = NULL, *dictitems = NULL;
|
||||||
PyObject *copy_reg = NULL, *newobj = NULL, *res = NULL;
|
PyObject *copyreg = NULL, *newobj = NULL, *res = NULL;
|
||||||
Py_ssize_t i, n;
|
Py_ssize_t i, n;
|
||||||
|
|
||||||
cls = PyObject_GetAttrString(obj, "__class__");
|
cls = PyObject_GetAttrString(obj, "__class__");
|
||||||
|
@ -3105,10 +3105,10 @@ reduce_2(PyObject *obj)
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_reg = import_copy_reg();
|
copyreg = import_copyreg();
|
||||||
if (copy_reg == NULL)
|
if (copyreg == NULL)
|
||||||
goto end;
|
goto end;
|
||||||
newobj = PyObject_GetAttrString(copy_reg, "__newobj__");
|
newobj = PyObject_GetAttrString(copyreg, "__newobj__");
|
||||||
if (newobj == NULL)
|
if (newobj == NULL)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
@ -3135,7 +3135,7 @@ reduce_2(PyObject *obj)
|
||||||
Py_XDECREF(names);
|
Py_XDECREF(names);
|
||||||
Py_XDECREF(listitems);
|
Py_XDECREF(listitems);
|
||||||
Py_XDECREF(dictitems);
|
Py_XDECREF(dictitems);
|
||||||
Py_XDECREF(copy_reg);
|
Py_XDECREF(copyreg);
|
||||||
Py_XDECREF(newobj);
|
Py_XDECREF(newobj);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -3158,17 +3158,17 @@ reduce_2(PyObject *obj)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_common_reduce(PyObject *self, int proto)
|
_common_reduce(PyObject *self, int proto)
|
||||||
{
|
{
|
||||||
PyObject *copy_reg, *res;
|
PyObject *copyreg, *res;
|
||||||
|
|
||||||
if (proto >= 2)
|
if (proto >= 2)
|
||||||
return reduce_2(self);
|
return reduce_2(self);
|
||||||
|
|
||||||
copy_reg = import_copy_reg();
|
copyreg = import_copyreg();
|
||||||
if (!copy_reg)
|
if (!copyreg)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
res = PyEval_CallMethod(copy_reg, "_reduce_ex", "(Oi)", self, proto);
|
res = PyEval_CallMethod(copyreg, "_reduce_ex", "(Oi)", self, proto);
|
||||||
Py_DECREF(copy_reg);
|
Py_DECREF(copyreg);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue