mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
Implement find_class() without exec statement.
This commit is contained in:
parent
c69955343c
commit
efd3a3a843
1 changed files with 2 additions and 4 deletions
|
@ -465,14 +465,12 @@ class Unpickler:
|
||||||
dispatch[CLASS] = load_class
|
dispatch[CLASS] = load_class
|
||||||
|
|
||||||
def find_class(self, module, name):
|
def find_class(self, module, name):
|
||||||
env = {}
|
|
||||||
try:
|
try:
|
||||||
exec 'from %s import %s' % (module, name) in env
|
klass = getattr(__import__(module), name)
|
||||||
except ImportError:
|
except (ImportError, AttributeError):
|
||||||
raise SystemError, \
|
raise SystemError, \
|
||||||
"Failed to import class %s from module %s" % \
|
"Failed to import class %s from module %s" % \
|
||||||
(name, module)
|
(name, module)
|
||||||
klass = env[name]
|
|
||||||
if type(klass) is BuiltinFunctionType:
|
if type(klass) is BuiltinFunctionType:
|
||||||
raise SystemError, \
|
raise SystemError, \
|
||||||
"Imported object %s from module %s is not a class" % \
|
"Imported object %s from module %s is not a class" % \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue