From efd3a3a843b15c05696ba4ac8c23b00d9d9a24ce Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 14 Mar 1997 04:21:10 +0000 Subject: [PATCH] Implement find_class() without exec statement. --- Lib/pickle.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/pickle.py b/Lib/pickle.py index 28f8f901d12..bfe49f91295 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" % \