From 484f53224d682a126c42a4ff1ecf4a580c3f88ba Mon Sep 17 00:00:00 2001 From: Michele Comitini Date: Mon, 15 Oct 2012 11:20:04 +0200 Subject: [PATCH] Reverted to the import using fromlist, but with working traceback. --- gluon/custom_import.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gluon/custom_import.py b/gluon/custom_import.py index b924ae83..c03d5bc4 100644 --- a/gluon/custom_import.py +++ b/gluon/custom_import.py @@ -56,9 +56,14 @@ def custom_importer(name, globals=None, locals=None, fromlist=None, level=-1): # import like "import x" or "import x.y" result = None for itemname in name.split("."): + new_mod = base_importer( + modules_prefix, globals,locals, [itemname], level) + try: + result = result or new_mod.__dict__[itemname] + print result + except KeyError, e: + raise ImportError, 'Cannot import module %s' % str(e) modules_prefix += "." + itemname - base_importer( - modules_prefix, globals,locals, [], level) return result else: # import like "from x import a, b, ..." @@ -69,7 +74,7 @@ def custom_importer(name, globals=None, locals=None, fromlist=None, level=-1): try: return NATIVE_IMPORTER(name,globals,locals,fromlist,level) except ImportError, e3: - raise ImportError, e1, import_tb.tb_next # there an import error in the module + raise ImportError, e1, import_tb # there an import error in the module except Exception, e2: raise e2 # there is an error in the module finally: