Commit 32988e04 authored by Julien Muchembled's avatar Julien Muchembled

Better use of __import__

parent 48e29a3f
...@@ -101,7 +101,7 @@ if IF == 'pdb': ...@@ -101,7 +101,7 @@ if IF == 'pdb':
def __init__(self, bp_list): def __init__(self, bp_list):
self._lock = threading.Lock() self._lock = threading.Lock()
for o, name in bp_list: for o, name in bp_list:
o = __import__(o, fromlist=1) o = __import__(o, fromlist=('*',), level=0)
x = name.split('.') x = name.split('.')
name = x.pop() name = x.pop()
for x in x: for x in x:
......
...@@ -173,7 +173,7 @@ class NeoTestRunner(unittest.TextTestResult): ...@@ -173,7 +173,7 @@ class NeoTestRunner(unittest.TextTestResult):
exclude != fnmatchcase(test_module, only)): exclude != fnmatchcase(test_module, only)):
continue continue
try: try:
test_module = __import__(test_module, globals(), locals(), ['*']) test_module = __import__(test_module, fromlist=('*',), level=0)
except ImportError, err: except ImportError, err:
self.failedImports[test_module] = err self.failedImports[test_module] = err
print "Import of %s failed : %s" % (test_module, err) print "Import of %s failed : %s" % (test_module, err)
......
...@@ -29,8 +29,7 @@ def getAdapterKlass(name): ...@@ -29,8 +29,7 @@ def getAdapterKlass(name):
module, name = DATABASE_MANAGER_DICT[name or 'MySQL'].split('.') module, name = DATABASE_MANAGER_DICT[name or 'MySQL'].split('.')
except KeyError: except KeyError:
raise DatabaseFailure('Cannot find a database adapter <%s>' % name) raise DatabaseFailure('Cannot find a database adapter <%s>' % name)
module = getattr(__import__(__name__, fromlist=[module], level=1), module) return getattr(__import__(module, globals(), level=1), name)
return getattr(module, name)
def buildDatabaseManager(name, args=(), kw={}): def buildDatabaseManager(name, args=(), kw={}):
return getAdapterKlass(name)(*args, **kw) return getAdapterKlass(name)(*args, **kw)
...@@ -125,7 +125,7 @@ class NEOProcess(object): ...@@ -125,7 +125,7 @@ class NEOProcess(object):
def __init__(self, command, uuid, arg_dict): def __init__(self, command, uuid, arg_dict):
try: try:
__import__('neo.scripts.' + command) __import__('neo.scripts.' + command, level=0)
except ImportError: except ImportError:
raise NotFound, '%s not found' % (command) raise NotFound, '%s not found' % (command)
self.command = command self.command = command
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment