diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-12-27 09:30:39 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2008-12-27 09:30:39 (GMT) |
commit | 3cfcab95924b089d4ba3844db05fa2cb913da0ba (patch) | |
tree | 8870fe804fbb8aefcddb8e009377b3dd5a7678f2 /Lib/pickle.py | |
parent | 44531cb2dbb7d752b98b2b8195f759a559973612 (diff) | |
download | cpython-3cfcab95924b089d4ba3844db05fa2cb913da0ba.zip cpython-3cfcab95924b089d4ba3844db05fa2cb913da0ba.tar.gz cpython-3cfcab95924b089d4ba3844db05fa2cb913da0ba.tar.bz2 |
Fix issue #4374: Pickle tests fail w/o _pickle extension.
Add an initialization check to mimic the interface of _pickle.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index 37c3d52..201dc99 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -222,6 +222,11 @@ class _Pickler: def dump(self, obj): """Write a pickled representation of obj to the open file.""" + # Check whether Pickler was initialized correctly. This is + # only needed to mimic the behavior of _pickle.Pickler.dump(). + if not hasattr(self, "write"): + raise PicklingError("Pickler.__init__() was not called by " + "%s.__init__()" % (self.__class__.__name__,)) if self.proto >= 2: self.write(PROTO + bytes([self.proto])) self.save(obj) @@ -789,6 +794,11 @@ class _Unpickler: Return the reconstituted object hierarchy specified in the file. """ + # Check whether Unpickler was initialized correctly. This is + # only needed to mimic the behavior of _pickle.Unpickler.dump(). + if not hasattr(self, "read"): + raise UnpicklingError("Unpickler.__init__() was not called by " + "%s.__init__()" % (self.__class__.__name__,)) self.mark = object() # any new unique object self.stack = [] self.append = self.stack.append |