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()
*__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. */
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;
INIT_STR(append);
INIT_STR(read);
INIT_STR(readline);
- INIT_STR(copyreg);
INIT_STR(dispatch_table);
if (!( copyreg = PyImport_ImportModule("copy_reg")))