Implement find_class() without exec statement.

This commit is contained in:
Guido van Rossum 1997-03-14 04:21:10 +00:00
parent c69955343c
commit efd3a3a843
1 changed files with 2 additions and 4 deletions

View File

@ -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" % \