]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 7128: Removed reference to the non-existent copyreg module.
authorAlexandre Vassalotti <alexandre@peadrop.com>
Tue, 24 Nov 2009 17:53:23 +0000 (17:53 +0000)
committerAlexandre Vassalotti <alexandre@peadrop.com>
Tue, 24 Nov 2009 17:53:23 +0000 (17:53 +0000)
The reference to copyreg was a unnoticed leftover from the compatibility
support for the grand renaming of the standard library in Python 3. The
compatibility support was reverted in r63493, but not completely as this
patch shows.

Based on a patch by Amaury Forgeot d'Arc.

Lib/test/pickletester.py
Modules/cPickle.c

index 8f96d74271cadb8f2965c5ecb81e8c42c390ef4e..04bb84233ea76a2c26872fbbcde9473d3e37a21a 100644 (file)
@@ -1091,6 +1091,16 @@ class AbstractPickleModuleTests(unittest.TestCase):
         s = StringIO.StringIO("X''.")
         self.assertRaises(EOFError, self.module.load, s)
 
+    def test_restricted(self):
+        # issue7128: cPickle failed in restricted mode
+        builtins = {self.module.__name__: self.module,
+                    '__import__': __import__}
+        d = {}
+        teststr = "def f(): {0}.dumps(0)".format(self.module.__name__)
+        exec teststr in {'__builtins__': builtins}, d
+        d['f']()
+
+
 class AbstractPersistentPicklerTests(unittest.TestCase):
 
     # This class defines persistent_id() and persistent_load()
index ab59b7691e90ca5ac7010aef156ab6da11f5dd61..f97959b2b5c7ac1361fa14b04f587cb006b2225c 100644 (file)
@@ -132,7 +132,7 @@ static PyObject *__class___str, *__getinitargs___str, *__dict___str,
   *__reduce_ex___str,
   *write_str, *append_str,
   *read_str, *readline_str, *__main___str, 
-  *copyreg_str, *dispatch_table_str;
+  *dispatch_table_str;
 
 /*************************************************************************
  Internal Data type for pickle data.                                     */
@@ -3069,7 +3069,7 @@ newPicklerobject(PyObject *file, int proto)
 
        if (PyEval_GetRestricted()) {
                /* Restricted execution, get private tables */
-               PyObject *m = PyImport_Import(copyreg_str);
+               PyObject *m = PyImport_ImportModule("copy_reg");
 
                if (m == NULL)
                        goto err;
@@ -5852,7 +5852,6 @@ init_stuff(PyObject *module_dict)
        INIT_STR(append);
        INIT_STR(read);
        INIT_STR(readline);
-       INIT_STR(copyreg);
        INIT_STR(dispatch_table);
 
        if (!( copyreg = PyImport_ImportModule("copy_reg")))