diff options
author | Guido van Rossum <guido@python.org> | 2001-08-17 18:49:52 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-08-17 18:49:52 (GMT) |
commit | b0a98e9c9462237706578a5180c0f83abd13a1fa (patch) | |
tree | 5f8d8fe1413f45c0f287564248b5e6324a08c188 /Lib | |
parent | 339d0f720e86dc34837547c90d3003a4a68d7d46 (diff) | |
download | cpython-b0a98e9c9462237706578a5180c0f83abd13a1fa.zip cpython-b0a98e9c9462237706578a5180c0f83abd13a1fa.tar.gz cpython-b0a98e9c9462237706578a5180c0f83abd13a1fa.tar.bz2 |
Address SF #451547. The approach is a bit draconian: any object that
is pickled as a global must now exist by the name under which it is
pickled, otherwise the pickling fails. Previously, such things would
fail on unpickling, or unpickle as the wrong global object. I'm
hoping that this won't break existing code that is playing tricks with
this.
I need a volunteer to do this for cPickle too.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pickle.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index c92dac2..8be7a8d 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -497,6 +497,20 @@ class Pickler: except AttributeError: module = whichmodule(object, name) + try: + __import__(module) + mod = sys.modules[module] + klass = getattr(mod, name) + except (ImportError, KeyError, AttributeError): + raise PicklingError( + "Can't pickle %r: it's not found as %s.%s" % + (object, module, name)) + else: + if klass is not object: + raise PicklingError( + "Can't pickle %r: it's not the same object as %s.%s" % + (object, module, name)) + memo_len = len(memo) write(GLOBAL + module + '\n' + name + '\n' + self.put(memo_len)) |