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.
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index e1bc078..ed3b626 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -2,7 +2,7 @@
import pickle
import cPickle
import pickletools
-import copy_reg
+import copyreg
from test.test_support import TestFailed, have_unicode, TESTFN, \
run_with_locale
@@ -44,21 +44,21 @@
# there is one).
def __init__(self, code):
self.code = code
- if code in copy_reg._inverted_registry:
- self.pair = copy_reg._inverted_registry[code]
- copy_reg.remove_extension(self.pair[0], self.pair[1], code)
+ if code in copyreg._inverted_registry:
+ self.pair = copyreg._inverted_registry[code]
+ copyreg.remove_extension(self.pair[0], self.pair[1], code)
else:
self.pair = None
# Restore previous registration for code.
def restore(self):
code = self.code
- curpair = copy_reg._inverted_registry.get(code)
+ curpair = copyreg._inverted_registry.get(code)
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
if pair is not None:
- copy_reg.add_extension(pair[0], pair[1], code)
+ copyreg.add_extension(pair[0], pair[1], code)
class C:
def __cmp__(self, other):
@@ -690,14 +690,14 @@
self.assertEqual(B(x), B(y), 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
# (EXT[124]) under proto 2, and not in proto 1.
def produce_global_ext(self, extcode, opcode):
e = ExtensionSaver(extcode)
try:
- copy_reg.add_extension(__name__, "MyList", extcode)
+ copyreg.add_extension(__name__, "MyList", extcode)
x = MyList([1, 2, 3])
x.foo = 42
x.bar = "hello"
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 7aa22ed..85df78e 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -629,7 +629,7 @@
def dash_R(the_module, test, indirect_test, huntrleaks):
# This code is hackish and inelegant, but it seems to do the job.
- import copy_reg, _abcoll, io
+ import copyreg, _abcoll, io
if not hasattr(sys, 'gettotalrefcount'):
raise Exception("Tracking reference leaks requires a debug build "
@@ -637,7 +637,7 @@
# Save current values for dash_R_cleanup() to restore.
fs = warnings.filters[:]
- ps = copy_reg.dispatch_table.copy()
+ ps = copyreg.dispatch_table.copy()
pic = sys.path_importer_cache.copy()
abcs = {}
modules = _abcoll, io
@@ -677,7 +677,7 @@
refrep.close()
def dash_R_cleanup(fs, ps, pic, abcs):
- import gc, copy_reg
+ import gc, copyreg
import _strptime, linecache
dircache = test_support.import_module('dircache', deprecated=True)
import urlparse, urllib, urllib2, mimetypes, doctest
@@ -691,8 +691,8 @@
# Restore some original values.
warnings.filters[:] = fs
- copy_reg.dispatch_table.clear()
- copy_reg.dispatch_table.update(ps)
+ copyreg.dispatch_table.clear()
+ copyreg.dispatch_table.update(ps)
sys.path_importer_cache.clear()
sys.path_importer_cache.update(pic)
diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py
index 1076c61..9c5e1f3 100644
--- a/Lib/test/test___all__.py
+++ b/Lib/test/test___all__.py
@@ -61,7 +61,7 @@
self.check_all("commands")
self.check_all("compileall")
self.check_all("copy")
- self.check_all("copy_reg")
+ self.check_all("copyreg")
self.check_all("csv")
self.check_all("dbhash")
self.check_all("decimal")
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index d2899bd..8645ba1 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -1,7 +1,7 @@
"""Unit tests for the copy module."""
import copy
-import copy_reg
+import copyreg
import unittest
from test import test_support
@@ -42,7 +42,7 @@
return (C, (obj.foo,))
x = C(42)
self.assertRaises(TypeError, copy.copy, x)
- copy_reg.pickle(C, pickle_C, C)
+ copyreg.pickle(C, pickle_C, C)
y = copy.copy(x)
def test_copy_reduce_ex(self):
@@ -215,7 +215,7 @@
return (C, (obj.foo,))
x = C(42)
self.assertRaises(TypeError, copy.deepcopy, x)
- copy_reg.pickle(C, pickle_C, C)
+ copyreg.pickle(C, pickle_C, C)
y = copy.deepcopy(x)
def test_deepcopy_reduce_ex(self):
diff --git a/Lib/test/test_copy_reg.py b/Lib/test/test_copy_reg.py
deleted file mode 100644
index c3d3964..0000000
--- a/Lib/test/test_copy_reg.py
+++ /dev/null
@@ -1,121 +0,0 @@
-import copy_reg
-import unittest
-
-from test import test_support
-from test.pickletester import ExtensionSaver
-
-class C:
- pass
-
-
-class WithoutSlots(object):
- pass
-
-class WithWeakref(object):
- __slots__ = ('__weakref__',)
-
-class WithPrivate(object):
- __slots__ = ('__spam',)
-
-class WithSingleString(object):
- __slots__ = 'spam'
-
-class WithInherited(WithSingleString):
- __slots__ = ('eggs',)
-
-
-class CopyRegTestCase(unittest.TestCase):
-
- def test_class(self):
- self.assertRaises(TypeError, copy_reg.pickle,
- C, None, None)
-
- def test_noncallable_reduce(self):
- self.assertRaises(TypeError, copy_reg.pickle,
- type(1), "not a callable")
-
- def test_noncallable_constructor(self):
- self.assertRaises(TypeError, copy_reg.pickle,
- type(1), int, "not a callable")
-
- def test_bool(self):
- import copy
- self.assertEquals(True, copy.copy(True))
-
- def test_extension_registry(self):
- mod, func, code = 'junk1 ', ' junk2', 0xabcd
- e = ExtensionSaver(code)
- try:
- # Shouldn't be in registry now.
- self.assertRaises(ValueError, copy_reg.remove_extension,
- mod, func, code)
- copy_reg.add_extension(mod, func, code)
- # Should be in the registry.
- self.assert_(copy_reg._extension_registry[mod, func] == code)
- self.assert_(copy_reg._inverted_registry[code] == (mod, func))
- # Shouldn't be in the cache.
- self.assert_(code not in copy_reg._extension_cache)
- # Redundant registration should be OK.
- copy_reg.add_extension(mod, func, code) # shouldn't blow up
- # Conflicting code.
- self.assertRaises(ValueError, copy_reg.add_extension,
- mod, func, code + 1)
- self.assertRaises(ValueError, copy_reg.remove_extension,
- mod, func, code + 1)
- # Conflicting module name.
- self.assertRaises(ValueError, copy_reg.add_extension,
- mod[1:], func, code )
- self.assertRaises(ValueError, copy_reg.remove_extension,
- mod[1:], func, code )
- # Conflicting function name.
- self.assertRaises(ValueError, copy_reg.add_extension,
- mod, func[1:], code)
- self.assertRaises(ValueError, copy_reg.remove_extension,
- mod, func[1:], code)
- # Can't remove one that isn't registered at all.
- if code + 1 not in copy_reg._inverted_registry:
- self.assertRaises(ValueError, copy_reg.remove_extension,
- mod[1:], func[1:], code + 1)
-
- finally:
- e.restore()
-
- # Shouldn't be there anymore.
- self.assert_((mod, func) not in copy_reg._extension_registry)
- # The code *may* be in copy_reg._extension_registry, though, if
- # we happened to pick on a registered code. So don't check for
- # that.
-
- # Check valid codes at the limits.
- for code in 1, 0x7fffffff:
- e = ExtensionSaver(code)
- try:
- copy_reg.add_extension(mod, func, code)
- copy_reg.remove_extension(mod, func, code)
- finally:
- e.restore()
-
- # Ensure invalid codes blow up.
- for code in -1, 0, 0x80000000L:
- self.assertRaises(ValueError, copy_reg.add_extension,
- mod, func, code)
-
- def test_slotnames(self):
- self.assertEquals(copy_reg._slotnames(WithoutSlots), [])
- self.assertEquals(copy_reg._slotnames(WithWeakref), [])
- expected = ['_WithPrivate__spam']
- self.assertEquals(copy_reg._slotnames(WithPrivate), expected)
- self.assertEquals(copy_reg._slotnames(WithSingleString), ['spam'])
- expected = ['eggs', 'spam']
- expected.sort()
- result = copy_reg._slotnames(WithInherited)
- result.sort()
- self.assertEquals(result, expected)
-
-
-def test_main():
- test_support.run_unittest(CopyRegTestCase)
-
-
-if __name__ == "__main__":
- test_main()
diff --git a/Lib/test/test_copyreg.py b/Lib/test/test_copyreg.py
new file mode 100644
index 0000000..0b42128
--- /dev/null
+++ b/Lib/test/test_copyreg.py
@@ -0,0 +1,121 @@
+import copyreg
+import unittest
+
+from test import test_support
+from test.pickletester import ExtensionSaver
+
+class C:
+ pass
+
+
+class WithoutSlots(object):
+ pass
+
+class WithWeakref(object):
+ __slots__ = ('__weakref__',)
+
+class WithPrivate(object):
+ __slots__ = ('__spam',)
+
+class WithSingleString(object):
+ __slots__ = 'spam'
+
+class WithInherited(WithSingleString):
+ __slots__ = ('eggs',)
+
+
+class CopyRegTestCase(unittest.TestCase):
+
+ def test_class(self):
+ self.assertRaises(TypeError, copyreg.pickle,
+ C, None, None)
+
+ def test_noncallable_reduce(self):
+ self.assertRaises(TypeError, copyreg.pickle,
+ type(1), "not a callable")
+
+ def test_noncallable_constructor(self):
+ self.assertRaises(TypeError, copyreg.pickle,
+ type(1), int, "not a callable")
+
+ def test_bool(self):
+ import copy
+ self.assertEquals(True, copy.copy(True))
+
+ def test_extension_registry(self):
+ mod, func, code = 'junk1 ', ' junk2', 0xabcd
+ e = ExtensionSaver(code)
+ try:
+ # Shouldn't be in registry now.
+ self.assertRaises(ValueError, copyreg.remove_extension,
+ mod, func, code)
+ copyreg.add_extension(mod, func, code)
+ # Should be in the registry.
+ self.assert_(copyreg._extension_registry[mod, func] == code)
+ self.assert_(copyreg._inverted_registry[code] == (mod, func))
+ # Shouldn't be in the cache.
+ self.assert_(code not in copyreg._extension_cache)
+ # Redundant registration should be OK.
+ copyreg.add_extension(mod, func, code) # shouldn't blow up
+ # Conflicting code.
+ self.assertRaises(ValueError, copyreg.add_extension,
+ mod, func, code + 1)
+ self.assertRaises(ValueError, copyreg.remove_extension,
+ mod, func, code + 1)
+ # Conflicting module name.
+ self.assertRaises(ValueError, copyreg.add_extension,
+ mod[1:], func, code )
+ self.assertRaises(ValueError, copyreg.remove_extension,
+ mod[1:], func, code )
+ # Conflicting function name.
+ self.assertRaises(ValueError, copyreg.add_extension,
+ mod, func[1:], code)
+ self.assertRaises(ValueError, copyreg.remove_extension,
+ mod, func[1:], code)
+ # Can't remove one that isn't registered at all.
+ if code + 1 not in copyreg._inverted_registry:
+ self.assertRaises(ValueError, copyreg.remove_extension,
+ mod[1:], func[1:], code + 1)
+
+ finally:
+ e.restore()
+
+ # Shouldn't be there anymore.
+ self.assert_((mod, func) not in copyreg._extension_registry)
+ # The code *may* be in copyreg._extension_registry, though, if
+ # we happened to pick on a registered code. So don't check for
+ # that.
+
+ # Check valid codes at the limits.
+ for code in 1, 0x7fffffff:
+ e = ExtensionSaver(code)
+ try:
+ copyreg.add_extension(mod, func, code)
+ copyreg.remove_extension(mod, func, code)
+ finally:
+ e.restore()
+
+ # Ensure invalid codes blow up.
+ for code in -1, 0, 0x80000000L:
+ self.assertRaises(ValueError, copyreg.add_extension,
+ mod, func, code)
+
+ def test_slotnames(self):
+ self.assertEquals(copyreg._slotnames(WithoutSlots), [])
+ self.assertEquals(copyreg._slotnames(WithWeakref), [])
+ expected = ['_WithPrivate__spam']
+ self.assertEquals(copyreg._slotnames(WithPrivate), expected)
+ self.assertEquals(copyreg._slotnames(WithSingleString), ['spam'])
+ expected = ['eggs', 'spam']
+ expected.sort()
+ result = copyreg._slotnames(WithInherited)
+ result.sort()
+ self.assertEquals(result, expected)
+
+
+def test_main():
+ test_support.run_unittest(CopyRegTestCase)
+
+
+if __name__ == "__main__":
+ test_main()