Index: Modules/cPickle.c =================================================================== --- Modules/cPickle.c (revision 69792) +++ Modules/cPickle.c (working copy) @@ -132,7 +132,7 @@ *__reduce_ex___str, *write_str, *append_str, *read_str, *readline_str, *__main___str, - *copyreg_str, *dispatch_table_str; + *copy_reg_str, *dispatch_table_str; /************************************************************************* Internal Data type for pickle data. */ @@ -2979,7 +2979,7 @@ if (PyEval_GetRestricted()) { /* Restricted execution, get private tables */ - PyObject *m = PyImport_Import(copyreg_str); + PyObject *m = PyImport_Import(copy_reg_str); if (m == NULL) goto err; @@ -5728,7 +5728,7 @@ INIT_STR(append); INIT_STR(read); INIT_STR(readline); - INIT_STR(copyreg); + INIT_STR(copy_reg); INIT_STR(dispatch_table); if (!( copyreg = PyImport_ImportModule("copy_reg"))) Index: Lib/test/test_cpickle.py =================================================================== --- Lib/test/test_cpickle.py (revision 68667) +++ Lib/test/test_cpickle.py (working copy) @@ -90,6 +90,13 @@ b = self.loads(self.dumps(a)) self.assertEqual(a, b) + def test_restricted(self): + # issue7128: cPickle failed in restricted mode + builtins = {'cPickle': cPickle, '__import__': __import__} + d = {} + exec "def f(): cPickle.dumps(0)" in {'__builtins__': builtins}, d + d['f']() + class Node(object): pass