From: Guido van Rossum Date: Fri, 14 Mar 1997 04:21:10 +0000 (+0000) Subject: Implement find_class() without exec statement. X-Git-Tag: v1.5a1~284 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=efd3a3a843b15c05696ba4ac8c23b00d9d9a24ce;p=python Implement find_class() without exec statement. --- diff --git a/Lib/pickle.py b/Lib/pickle.py index 28f8f901d1..bfe49f9129 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -465,14 +465,12 @@ class Unpickler: dispatch[CLASS] = load_class def find_class(self, module, name): - env = {} try: - exec 'from %s import %s' % (module, name) in env - except ImportError: + klass = getattr(__import__(module), name) + except (ImportError, AttributeError): raise SystemError, \ "Failed to import class %s from module %s" % \ (name, module) - klass = env[name] if type(klass) is BuiltinFunctionType: raise SystemError, \ "Imported object %s from module %s is not a class" % \