mirror of
https://github.com/python/cpython.git
synced 2025-07-30 06:34:15 +00:00
Revert copy_reg -> copyreg rename.
This commit is contained in:
parent
06d2a2cb0e
commit
dffbf5f542
23 changed files with 83 additions and 94 deletions
|
@ -63,7 +63,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:`copyreg` registration
|
methods. The :mod:`copy` module does not use the :mod:`copy_reg` registration
|
||||||
module.
|
module.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
|
|
|
@ -1,23 +1,20 @@
|
||||||
:mod:`copyreg` --- Register :mod:`pickle` support functions
|
:mod:`copy_reg` --- Register :mod:`pickle` support functions
|
||||||
===========================================================
|
============================================================
|
||||||
|
|
||||||
.. module:: copy_reg
|
.. module:: copy_reg
|
||||||
:synopsis: Old name for the copyreg module.
|
|
||||||
|
|
||||||
.. module:: copyreg
|
|
||||||
:synopsis: Register pickle support functions.
|
:synopsis: Register pickle support functions.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
The :mod:`copy_reg` module has been renamed to :mod:`copyreg` in Python 3.0.
|
The :mod:`copy_reg` module has been renamed to :mod:`copyreg` in Python 3.0.
|
||||||
It is importable under both names in Python 2.6 and the rest of the 2.x
|
The :term:`2to3` tool will automatically adapt imports when converting your
|
||||||
series.
|
sources to 3.0.
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
module: pickle
|
module: pickle
|
||||||
module: cPickle
|
module: cPickle
|
||||||
module: copy
|
module: copy
|
||||||
|
|
||||||
The :mod:`copyreg` module provides support for the :mod:`pickle` and
|
The :mod:`copy_reg` 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
|
|
@ -97,7 +97,7 @@ Sample output (may vary depending on the architecture)::
|
||||||
|
|
||||||
Loaded modules:
|
Loaded modules:
|
||||||
_types:
|
_types:
|
||||||
copyreg: _inverted_registry,_slotnames,__all__
|
copy_reg: _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
|
||||||
copyreg.rst
|
copy_reg.rst
|
||||||
shelve.rst
|
shelve.rst
|
||||||
marshal.rst
|
marshal.rst
|
||||||
anydbm.rst
|
anydbm.rst
|
||||||
|
|
|
@ -535,7 +535,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:`copyreg` module. This
|
pickled, is to register the callable with the :mod:`copy_reg` 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
|
||||||
|
@ -786,7 +786,7 @@ the same process or a new process. ::
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
Module :mod:`copyreg`
|
Module :mod:`copy_reg`
|
||||||
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 copyreg import dispatch_table
|
from copy_reg import dispatch_table
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -13,7 +13,7 @@ dispatch_table = {}
|
||||||
|
|
||||||
def pickle(ob_type, pickle_function, constructor_ob=None):
|
def pickle(ob_type, pickle_function, constructor_ob=None):
|
||||||
if type(ob_type) is _ClassType:
|
if type(ob_type) is _ClassType:
|
||||||
raise TypeError("copyreg is not intended for use with classes")
|
raise TypeError("copy_reg is not intended for use with classes")
|
||||||
|
|
||||||
if not hasattr(pickle_function, '__call__'):
|
if not hasattr(pickle_function, '__call__'):
|
||||||
raise TypeError("reduction functions must be callable")
|
raise TypeError("reduction functions must be callable")
|
|
@ -37,7 +37,7 @@ import cPickle as pickle
|
||||||
import threading
|
import threading
|
||||||
import queue
|
import queue
|
||||||
import traceback
|
import traceback
|
||||||
import copyreg
|
import copy_reg
|
||||||
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)
|
||||||
|
|
||||||
copyreg.pickle(types.CodeType, pickle_code, unpickle_code)
|
copy_reg.pickle(types.CodeType, pickle_code, unpickle_code)
|
||||||
# copyreg.pickle(types.FunctionType, pickle_function, unpickle_function)
|
# copy_reg.pickle(types.FunctionType, pickle_function, unpickle_function)
|
||||||
|
|
||||||
BUFSIZE = 8*1024
|
BUFSIZE = 8*1024
|
||||||
LOCALHOST = '127.0.0.1'
|
LOCALHOST = '127.0.0.1'
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
import sys
|
|
||||||
from warnings import warnpy3k
|
|
||||||
|
|
||||||
warnpy3k("the copy_reg module has been renamed "
|
|
||||||
"to 'copyreg' in Python 3.0", stacklevel=2)
|
|
||||||
|
|
||||||
import copyreg
|
|
||||||
sys.modules[__name__] = copyreg
|
|
|
@ -715,7 +715,7 @@ if _exists("fork"):
|
||||||
return p.stdin, p.stdout
|
return p.stdin, p.stdout
|
||||||
__all__.append("popen4")
|
__all__.append("popen4")
|
||||||
|
|
||||||
import copyreg as _copy_reg
|
import copy_reg as _copy_reg
|
||||||
|
|
||||||
def _make_stat_result(tup, dict):
|
def _make_stat_result(tup, dict):
|
||||||
return stat_result(tup, dict)
|
return stat_result(tup, dict)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Create portable serialized representations of Python objects.
|
"""Create portable serialized representations of Python objects.
|
||||||
|
|
||||||
See module cPickle for a (much) faster implementation.
|
See module cPickle for a (much) faster implementation.
|
||||||
See module copyreg for a mechanism for registering custom picklers.
|
See module copy_reg for a mechanism for registering custom picklers.
|
||||||
See module pickletools source for extensive comments.
|
See module pickletools source for extensive comments.
|
||||||
|
|
||||||
Classes:
|
Classes:
|
||||||
|
@ -27,8 +27,8 @@ Misc variables:
|
||||||
__version__ = "$Revision$" # Code version
|
__version__ = "$Revision$" # Code version
|
||||||
|
|
||||||
from types import *
|
from types import *
|
||||||
from copyreg import dispatch_table
|
from copy_reg import dispatch_table
|
||||||
from copyreg import _extension_registry, _inverted_registry, _extension_cache
|
from copy_reg import _extension_registry, _inverted_registry, _extension_cache
|
||||||
import marshal
|
import marshal
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
|
@ -295,7 +295,7 @@ class Pickler:
|
||||||
self.save_global(obj)
|
self.save_global(obj)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check copyreg.dispatch_table
|
# Check copy_reg.dispatch_table
|
||||||
reduce = dispatch_table.get(t)
|
reduce = dispatch_table.get(t)
|
||||||
if reduce:
|
if reduce:
|
||||||
rv = reduce(obj)
|
rv = reduce(obj)
|
||||||
|
|
|
@ -136,7 +136,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
|
||||||
copyreg.safe_constructors are removed from the unpickling code.
|
copy_reg.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.
|
||||||
"""
|
"""
|
||||||
|
@ -1525,7 +1525,7 @@ opcodes = [
|
||||||
BUILD opcode to apply __setstate__ to that argument.
|
BUILD opcode to apply __setstate__ to that argument.
|
||||||
|
|
||||||
If type(callable) is not ClassType, REDUCE complains unless the
|
If type(callable) is not ClassType, REDUCE complains unless the
|
||||||
callable has been registered with the copyreg module's
|
callable has been registered with the copy_reg 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
|
||||||
|
|
|
@ -278,12 +278,12 @@ def _subx(pattern, template):
|
||||||
|
|
||||||
# register myself for pickling
|
# register myself for pickling
|
||||||
|
|
||||||
import copyreg
|
import copy_reg
|
||||||
|
|
||||||
def _pickle(p):
|
def _pickle(p):
|
||||||
return _compile, (p.pattern, p.flags)
|
return _compile, (p.pattern, p.flags)
|
||||||
|
|
||||||
copyreg.pickle(_pattern_type, _pickle, _compile)
|
copy_reg.pickle(_pattern_type, _pickle, _compile)
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# experimental stuff (see python-dev discussions for details)
|
# experimental stuff (see python-dev discussions for details)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import unittest
|
||||||
import pickle
|
import pickle
|
||||||
import cPickle
|
import cPickle
|
||||||
import pickletools
|
import pickletools
|
||||||
import copyreg
|
import copy_reg
|
||||||
|
|
||||||
from test.test_support import TestFailed, have_unicode, TESTFN, \
|
from test.test_support import TestFailed, have_unicode, TESTFN, \
|
||||||
run_with_locale
|
run_with_locale
|
||||||
|
@ -44,21 +44,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 copyreg._inverted_registry:
|
if code in copy_reg._inverted_registry:
|
||||||
self.pair = copyreg._inverted_registry[code]
|
self.pair = copy_reg._inverted_registry[code]
|
||||||
copyreg.remove_extension(self.pair[0], self.pair[1], code)
|
copy_reg.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 = copyreg._inverted_registry.get(code)
|
curpair = copy_reg._inverted_registry.get(code)
|
||||||
if curpair is not None:
|
if curpair is not None:
|
||||||
copyreg.remove_extension(curpair[0], curpair[1], code)
|
copy_reg.remove_extension(curpair[0], curpair[1], code)
|
||||||
pair = self.pair
|
pair = self.pair
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
copyreg.add_extension(pair[0], pair[1], code)
|
copy_reg.add_extension(pair[0], pair[1], code)
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
|
@ -690,14 +690,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 copyreg, with extension code extcode. Pickle
|
# Register a type with copy_reg, 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:
|
||||||
copyreg.add_extension(__name__, "MyList", extcode)
|
copy_reg.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"
|
||||||
|
|
|
@ -629,7 +629,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 copyreg, _abcoll, io
|
import copy_reg, _abcoll, io
|
||||||
|
|
||||||
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 "
|
||||||
|
@ -637,7 +637,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 = copyreg.dispatch_table.copy()
|
ps = copy_reg.dispatch_table.copy()
|
||||||
pic = sys.path_importer_cache.copy()
|
pic = sys.path_importer_cache.copy()
|
||||||
abcs = {}
|
abcs = {}
|
||||||
modules = _abcoll, io
|
modules = _abcoll, io
|
||||||
|
@ -677,7 +677,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, copyreg
|
import gc, copy_reg
|
||||||
import _strptime, linecache
|
import _strptime, linecache
|
||||||
dircache = test_support.import_module('dircache', deprecated=True)
|
dircache = test_support.import_module('dircache', deprecated=True)
|
||||||
import urlparse, urllib, urllib2, mimetypes, doctest
|
import urlparse, urllib, urllib2, mimetypes, doctest
|
||||||
|
@ -691,8 +691,8 @@ def dash_R_cleanup(fs, ps, pic, abcs):
|
||||||
|
|
||||||
# Restore some original values.
|
# Restore some original values.
|
||||||
warnings.filters[:] = fs
|
warnings.filters[:] = fs
|
||||||
copyreg.dispatch_table.clear()
|
copy_reg.dispatch_table.clear()
|
||||||
copyreg.dispatch_table.update(ps)
|
copy_reg.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)
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,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("copyreg")
|
self.check_all("copy_reg")
|
||||||
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 copyreg
|
import copy_reg
|
||||||
|
|
||||||
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)
|
||||||
copyreg.pickle(C, pickle_C, C)
|
copy_reg.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)
|
||||||
copyreg.pickle(C, pickle_C, C)
|
copy_reg.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 copyreg
|
import copy_reg
|
||||||
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, copyreg.pickle,
|
self.assertRaises(TypeError, copy_reg.pickle,
|
||||||
C, None, None)
|
C, None, None)
|
||||||
|
|
||||||
def test_noncallable_reduce(self):
|
def test_noncallable_reduce(self):
|
||||||
self.assertRaises(TypeError, copyreg.pickle,
|
self.assertRaises(TypeError, copy_reg.pickle,
|
||||||
type(1), "not a callable")
|
type(1), "not a callable")
|
||||||
|
|
||||||
def test_noncallable_constructor(self):
|
def test_noncallable_constructor(self):
|
||||||
self.assertRaises(TypeError, copyreg.pickle,
|
self.assertRaises(TypeError, copy_reg.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, copyreg.remove_extension,
|
self.assertRaises(ValueError, copy_reg.remove_extension,
|
||||||
mod, func, code)
|
mod, func, code)
|
||||||
copyreg.add_extension(mod, func, code)
|
copy_reg.add_extension(mod, func, code)
|
||||||
# Should be in the registry.
|
# Should be in the registry.
|
||||||
self.assert_(copyreg._extension_registry[mod, func] == code)
|
self.assert_(copy_reg._extension_registry[mod, func] == code)
|
||||||
self.assert_(copyreg._inverted_registry[code] == (mod, func))
|
self.assert_(copy_reg._inverted_registry[code] == (mod, func))
|
||||||
# Shouldn't be in the cache.
|
# Shouldn't be in the cache.
|
||||||
self.assert_(code not in copyreg._extension_cache)
|
self.assert_(code not in copy_reg._extension_cache)
|
||||||
# Redundant registration should be OK.
|
# Redundant registration should be OK.
|
||||||
copyreg.add_extension(mod, func, code) # shouldn't blow up
|
copy_reg.add_extension(mod, func, code) # shouldn't blow up
|
||||||
# Conflicting code.
|
# Conflicting code.
|
||||||
self.assertRaises(ValueError, copyreg.add_extension,
|
self.assertRaises(ValueError, copy_reg.add_extension,
|
||||||
mod, func, code + 1)
|
mod, func, code + 1)
|
||||||
self.assertRaises(ValueError, copyreg.remove_extension,
|
self.assertRaises(ValueError, copy_reg.remove_extension,
|
||||||
mod, func, code + 1)
|
mod, func, code + 1)
|
||||||
# Conflicting module name.
|
# Conflicting module name.
|
||||||
self.assertRaises(ValueError, copyreg.add_extension,
|
self.assertRaises(ValueError, copy_reg.add_extension,
|
||||||
mod[1:], func, code )
|
mod[1:], func, code )
|
||||||
self.assertRaises(ValueError, copyreg.remove_extension,
|
self.assertRaises(ValueError, copy_reg.remove_extension,
|
||||||
mod[1:], func, code )
|
mod[1:], func, code )
|
||||||
# Conflicting function name.
|
# Conflicting function name.
|
||||||
self.assertRaises(ValueError, copyreg.add_extension,
|
self.assertRaises(ValueError, copy_reg.add_extension,
|
||||||
mod, func[1:], code)
|
mod, func[1:], code)
|
||||||
self.assertRaises(ValueError, copyreg.remove_extension,
|
self.assertRaises(ValueError, copy_reg.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 copyreg._inverted_registry:
|
if code + 1 not in copy_reg._inverted_registry:
|
||||||
self.assertRaises(ValueError, copyreg.remove_extension,
|
self.assertRaises(ValueError, copy_reg.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 copyreg._extension_registry)
|
self.assert_((mod, func) not in copy_reg._extension_registry)
|
||||||
# The code *may* be in copyreg._extension_registry, though, if
|
# The code *may* be in copy_reg._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:
|
||||||
copyreg.add_extension(mod, func, code)
|
copy_reg.add_extension(mod, func, code)
|
||||||
copyreg.remove_extension(mod, func, code)
|
copy_reg.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, 0x80000000L:
|
for code in -1, 0, 0x80000000L:
|
||||||
self.assertRaises(ValueError, copyreg.add_extension,
|
self.assertRaises(ValueError, copy_reg.add_extension,
|
||||||
mod, func, code)
|
mod, func, code)
|
||||||
|
|
||||||
def test_slotnames(self):
|
def test_slotnames(self):
|
||||||
self.assertEquals(copyreg._slotnames(WithoutSlots), [])
|
self.assertEquals(copy_reg._slotnames(WithoutSlots), [])
|
||||||
self.assertEquals(copyreg._slotnames(WithWeakref), [])
|
self.assertEquals(copy_reg._slotnames(WithWeakref), [])
|
||||||
expected = ['_WithPrivate__spam']
|
expected = ['_WithPrivate__spam']
|
||||||
self.assertEquals(copyreg._slotnames(WithPrivate), expected)
|
self.assertEquals(copy_reg._slotnames(WithPrivate), expected)
|
||||||
self.assertEquals(copyreg._slotnames(WithSingleString), ['spam'])
|
self.assertEquals(copy_reg._slotnames(WithSingleString), ['spam'])
|
||||||
expected = ['eggs', 'spam']
|
expected = ['eggs', 'spam']
|
||||||
expected.sort()
|
expected.sort()
|
||||||
result = copyreg._slotnames(WithInherited)
|
result = copy_reg._slotnames(WithInherited)
|
||||||
result.sort()
|
result.sort()
|
||||||
self.assertEquals(result, expected)
|
self.assertEquals(result, expected)
|
||||||
|
|
|
@ -215,7 +215,7 @@ class TestStdlibRemovals(unittest.TestCase):
|
||||||
|
|
||||||
class TestStdlibRenames(unittest.TestCase):
|
class TestStdlibRenames(unittest.TestCase):
|
||||||
|
|
||||||
renames = {'copy_reg': 'copyreg', 'Queue': 'queue',
|
renames = {'Queue': 'queue',
|
||||||
'SocketServer': 'socketserver',
|
'SocketServer': 'socketserver',
|
||||||
'ConfigParser': 'configparser',
|
'ConfigParser': 'configparser',
|
||||||
'repr': 'reprlib'}
|
'repr': 'reprlib'}
|
||||||
|
|
|
@ -1864,7 +1864,7 @@ commands Tools for executing UNIX commands .
|
||||||
compileall Force "compilation" of all .py files in a directory.
|
compileall Force "compilation" of all .py files in a directory.
|
||||||
configparser Configuration file parser (much like windows .ini files)
|
configparser Configuration file parser (much like windows .ini files)
|
||||||
copy Generic shallow and deep copying operations.
|
copy Generic shallow and deep copying operations.
|
||||||
copyreg Helper to provide extensibility for pickle/cPickle.
|
copy_reg Helper to provide extensibility for pickle/cPickle.
|
||||||
csv Read and write files with comma separated values.
|
csv Read and write files with comma separated values.
|
||||||
dbhash (g)dbm-compatible interface to bsdhash.hashopen.
|
dbhash (g)dbm-compatible interface to bsdhash.hashopen.
|
||||||
dircache Sorted list of files in a dir, using a cache.
|
dircache Sorted list of files in a dir, using a cache.
|
||||||
|
|
|
@ -105,18 +105,18 @@ static PyObject *BadPickleGet;
|
||||||
/* As the name says, an empty tuple. */
|
/* As the name says, an empty tuple. */
|
||||||
static PyObject *empty_tuple;
|
static PyObject *empty_tuple;
|
||||||
|
|
||||||
/* copyreg.dispatch_table, {type_object: pickling_function} */
|
/* copy_reg.dispatch_table, {type_object: pickling_function} */
|
||||||
static PyObject *dispatch_table;
|
static PyObject *dispatch_table;
|
||||||
|
|
||||||
/* For EXT[124] opcodes. */
|
/* For EXT[124] opcodes. */
|
||||||
/* copyreg._extension_registry, {(module_name, function_name): code} */
|
/* copy_reg._extension_registry, {(module_name, function_name): code} */
|
||||||
static PyObject *extension_registry;
|
static PyObject *extension_registry;
|
||||||
/* copyreg._inverted_registry, {code: (module_name, function_name)} */
|
/* copy_reg._inverted_registry, {code: (module_name, function_name)} */
|
||||||
static PyObject *inverted_registry;
|
static PyObject *inverted_registry;
|
||||||
/* copyreg._extension_cache, {code: object} */
|
/* copy_reg._extension_cache, {code: object} */
|
||||||
static PyObject *extension_cache;
|
static PyObject *extension_cache;
|
||||||
|
|
||||||
/* For looking up name pairs in copyreg._extension_registry. */
|
/* For looking up name pairs in copy_reg._extension_registry. */
|
||||||
static PyObject *two_tuple;
|
static PyObject *two_tuple;
|
||||||
|
|
||||||
static PyObject *__class___str, *__getinitargs___str, *__dict___str,
|
static PyObject *__class___str, *__getinitargs___str, *__dict___str,
|
||||||
|
@ -2477,7 +2477,7 @@ save(Picklerobject *self, PyObject *args, int pers_save)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a reduction callable, and call it. This may come from
|
/* Get a reduction callable, and call it. This may come from
|
||||||
* copyreg.dispatch_table, the object's __reduce_ex__ method,
|
* copy_reg.dispatch_table, the object's __reduce_ex__ method,
|
||||||
* or the object's __reduce__ method.
|
* or the object's __reduce__ method.
|
||||||
*/
|
*/
|
||||||
__reduce__ = PyDict_GetItem(dispatch_table, (PyObject *)type);
|
__reduce__ = PyDict_GetItem(dispatch_table, (PyObject *)type);
|
||||||
|
@ -5591,7 +5591,7 @@ init_stuff(PyObject *module_dict)
|
||||||
INIT_STR(copyreg);
|
INIT_STR(copyreg);
|
||||||
INIT_STR(dispatch_table);
|
INIT_STR(dispatch_table);
|
||||||
|
|
||||||
if (!( copyreg = PyImport_ImportModule("copyreg")))
|
if (!( copyreg = PyImport_ImportModule("copy_reg")))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* This is special because we want to use a different
|
/* This is special because we want to use a different
|
||||||
|
|
|
@ -3284,7 +3284,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("copyreg");
|
copyreg = PyImport_ImportModuleNoBlock("copy_reg");
|
||||||
if (copyreg != NULL) {
|
if (copyreg != NULL) {
|
||||||
PyObject *func, *pickler;
|
PyObject *func, *pickler;
|
||||||
|
|
||||||
|
|
|
@ -3058,7 +3058,7 @@ 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 copyreg for:
|
We fall back to helpers in copy_reg 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)
|
||||||
|
@ -3070,7 +3070,7 @@ import_copyreg(void)
|
||||||
static PyObject *copyreg_str;
|
static PyObject *copyreg_str;
|
||||||
|
|
||||||
if (!copyreg_str) {
|
if (!copyreg_str) {
|
||||||
copyreg_str = PyString_InternFromString("copyreg");
|
copyreg_str = PyString_InternFromString("copy_reg");
|
||||||
if (copyreg_str == NULL)
|
if (copyreg_str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3108,7 +3108,7 @@ slotnames(PyObject *cls)
|
||||||
!PyList_Check(slotnames))
|
!PyList_Check(slotnames))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"copyreg._slotnames didn't return a list or None");
|
"copy_reg._slotnames didn't return a list or None");
|
||||||
Py_DECREF(slotnames);
|
Py_DECREF(slotnames);
|
||||||
slotnames = NULL;
|
slotnames = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue