Implement appropriate __getnewargs__ for all immutable subclassable builtin

types.  The special handling for these can now be removed from save_newobj().
Add some testing for this.

Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
This commit is contained in:
Guido van Rossum 2003-01-29 17:58:45 +00:00
parent d3590f937f
commit 5d9113d8be
10 changed files with 133 additions and 19 deletions

View file

@ -11,9 +11,13 @@ from test.pickletester import AbstractPersistentPicklerTests
class PickleTests(AbstractPickleTests, AbstractPickleModuleTests, XXXTemp):
def setUp(self):
self.dumps = pickle.dumps
self.loads = pickle.loads
def dumps(self, arg, proto=0, fast=0):
# Ignore fast
return pickle.dumps(arg, proto)
def loads(self, buf):
# Ignore fast
return pickle.loads(buf)
module = pickle
error = KeyError
@ -22,9 +26,11 @@ class PicklerTests(AbstractPickleTests):
error = KeyError
def dumps(self, arg, proto=0):
def dumps(self, arg, proto=0, fast=0):
f = StringIO()
p = pickle.Pickler(f, proto)
if fast:
p.fast = fast
p.dump(arg)
f.seek(0)
return f.read()
@ -36,12 +42,14 @@ class PicklerTests(AbstractPickleTests):
class PersPicklerTests(AbstractPersistentPicklerTests):
def dumps(self, arg, proto=0):
def dumps(self, arg, proto=0, fast=0):
class PersPickler(pickle.Pickler):
def persistent_id(subself, obj):
return self.persistent_id(obj)
f = StringIO()
p = PersPickler(f, proto)
if fast:
p.fast = fast
p.dump(arg)
f.seek(0)
return f.read()