mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
revert the addition of _pickle because it was causing havok with 64-bit
This commit is contained in:
parent
f501942c76
commit
75f25f2c9a
12 changed files with 126 additions and 4695 deletions
|
@ -362,7 +362,7 @@ def create_data():
|
|||
return x
|
||||
|
||||
class AbstractPickleTests(unittest.TestCase):
|
||||
# Subclass must define self.dumps, self.loads.
|
||||
# Subclass must define self.dumps, self.loads, self.error.
|
||||
|
||||
_testdata = create_data()
|
||||
|
||||
|
@ -463,9 +463,8 @@ class AbstractPickleTests(unittest.TestCase):
|
|||
self.assertEqual(list(x[0].attr.keys()), [1])
|
||||
self.assert_(x[0].attr[1] is x)
|
||||
|
||||
def test_get(self):
|
||||
self.assertRaises(KeyError, self.loads, b'g0\np0')
|
||||
self.assertEquals(self.loads(b'((Kdtp0\nh\x00l.))'), [(100,), (100,)])
|
||||
def test_garyp(self):
|
||||
self.assertRaises(self.error, self.loads, b'garyp')
|
||||
|
||||
def test_insecure_strings(self):
|
||||
# XXX Some of these tests are temporarily disabled
|
||||
|
@ -956,7 +955,7 @@ class AbstractPickleModuleTests(unittest.TestCase):
|
|||
f = open(TESTFN, "wb")
|
||||
try:
|
||||
f.close()
|
||||
self.assertRaises(ValueError, pickle.dump, 123, f)
|
||||
self.assertRaises(ValueError, self.module.dump, 123, f)
|
||||
finally:
|
||||
os.remove(TESTFN)
|
||||
|
||||
|
@ -965,24 +964,24 @@ class AbstractPickleModuleTests(unittest.TestCase):
|
|||
f = open(TESTFN, "wb")
|
||||
try:
|
||||
f.close()
|
||||
self.assertRaises(ValueError, pickle.dump, 123, f)
|
||||
self.assertRaises(ValueError, self.module.dump, 123, f)
|
||||
finally:
|
||||
os.remove(TESTFN)
|
||||
|
||||
def test_highest_protocol(self):
|
||||
# Of course this needs to be changed when HIGHEST_PROTOCOL changes.
|
||||
self.assertEqual(pickle.HIGHEST_PROTOCOL, 3)
|
||||
self.assertEqual(self.module.HIGHEST_PROTOCOL, 3)
|
||||
|
||||
def test_callapi(self):
|
||||
from io import BytesIO
|
||||
f = BytesIO()
|
||||
# With and without keyword arguments
|
||||
pickle.dump(123, f, -1)
|
||||
pickle.dump(123, file=f, protocol=-1)
|
||||
pickle.dumps(123, -1)
|
||||
pickle.dumps(123, protocol=-1)
|
||||
pickle.Pickler(f, -1)
|
||||
pickle.Pickler(f, protocol=-1)
|
||||
self.module.dump(123, f, -1)
|
||||
self.module.dump(123, file=f, protocol=-1)
|
||||
self.module.dumps(123, -1)
|
||||
self.module.dumps(123, protocol=-1)
|
||||
self.module.Pickler(f, -1)
|
||||
self.module.Pickler(f, protocol=-1)
|
||||
|
||||
class AbstractPersistentPicklerTests(unittest.TestCase):
|
||||
|
||||
|
|
|
@ -7,42 +7,37 @@ from test.pickletester import AbstractPickleTests
|
|||
from test.pickletester import AbstractPickleModuleTests
|
||||
from test.pickletester import AbstractPersistentPicklerTests
|
||||
|
||||
try:
|
||||
import _pickle
|
||||
has_c_implementation = True
|
||||
except ImportError:
|
||||
has_c_implementation = False
|
||||
class PickleTests(AbstractPickleTests, AbstractPickleModuleTests):
|
||||
|
||||
module = pickle
|
||||
error = KeyError
|
||||
|
||||
class PickleTests(AbstractPickleModuleTests):
|
||||
pass
|
||||
def dumps(self, arg, proto=None):
|
||||
return pickle.dumps(arg, proto)
|
||||
|
||||
def loads(self, buf):
|
||||
return pickle.loads(buf)
|
||||
|
||||
class PyPicklerTests(AbstractPickleTests):
|
||||
class PicklerTests(AbstractPickleTests):
|
||||
|
||||
pickler = pickle._Pickler
|
||||
unpickler = pickle._Unpickler
|
||||
error = KeyError
|
||||
|
||||
def dumps(self, arg, proto=None):
|
||||
f = io.BytesIO()
|
||||
p = self.pickler(f, proto)
|
||||
p = pickle.Pickler(f, proto)
|
||||
p.dump(arg)
|
||||
f.seek(0)
|
||||
return bytes(f.read())
|
||||
|
||||
def loads(self, buf):
|
||||
f = io.BytesIO(buf)
|
||||
u = self.unpickler(f)
|
||||
u = pickle.Unpickler(f)
|
||||
return u.load()
|
||||
|
||||
|
||||
class PyPersPicklerTests(AbstractPersistentPicklerTests):
|
||||
|
||||
pickler = pickle._Pickler
|
||||
unpickler = pickle._Unpickler
|
||||
class PersPicklerTests(AbstractPersistentPicklerTests):
|
||||
|
||||
def dumps(self, arg, proto=None):
|
||||
class PersPickler(self.pickler):
|
||||
class PersPickler(pickle.Pickler):
|
||||
def persistent_id(subself, obj):
|
||||
return self.persistent_id(obj)
|
||||
f = io.BytesIO()
|
||||
|
@ -52,29 +47,19 @@ class PyPersPicklerTests(AbstractPersistentPicklerTests):
|
|||
return f.read()
|
||||
|
||||
def loads(self, buf):
|
||||
class PersUnpickler(self.unpickler):
|
||||
class PersUnpickler(pickle.Unpickler):
|
||||
def persistent_load(subself, obj):
|
||||
return self.persistent_load(obj)
|
||||
f = io.BytesIO(buf)
|
||||
u = PersUnpickler(f)
|
||||
return u.load()
|
||||
|
||||
|
||||
if has_c_implementation:
|
||||
class CPicklerTests(PyPicklerTests):
|
||||
pickler = _pickle.Pickler
|
||||
unpickler = _pickle.Unpickler
|
||||
|
||||
class CPersPicklerTests(PyPersPicklerTests):
|
||||
pickler = _pickle.Pickler
|
||||
unpickler = _pickle.Unpickler
|
||||
|
||||
|
||||
def test_main():
|
||||
tests = [PickleTests, PyPicklerTests, PyPersPicklerTests]
|
||||
if has_c_implementation:
|
||||
tests.extend([CPicklerTests, CPersPicklerTests])
|
||||
support.run_unittest(*tests)
|
||||
support.run_unittest(
|
||||
PickleTests,
|
||||
PicklerTests,
|
||||
PersPicklerTests
|
||||
)
|
||||
support.run_doctest(pickle)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -12,6 +12,8 @@ class OptimizedPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
|
|||
def loads(self, buf):
|
||||
return pickle.loads(buf)
|
||||
|
||||
module = pickle
|
||||
error = KeyError
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(OptimizedPickleTests)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue