summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py14
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))