From 5a0132d3ccb17ff8d49fe6a1b4ecdc24b2427198 Mon Sep 17 00:00:00 2001 From: prascle Date: Fri, 1 Dec 2006 09:30:15 +0000 Subject: [PATCH] PAL 14087 --- src/KERNEL_PY/import_hook.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/KERNEL_PY/import_hook.py b/src/KERNEL_PY/import_hook.py index e3e744a81..b8687498c 100755 --- a/src/KERNEL_PY/import_hook.py +++ b/src/KERNEL_PY/import_hook.py @@ -110,6 +110,17 @@ def set_shared_imported(name,module): shared_imported[name]=module #print "Module %s shared registered" % name,module +def import_module(partname, fqname, parent): + """ Try to import module fqname + It's parent is module parent and has name partname + """ + try: + m = sys.modules[fqname] + except KeyError: + pass + else: + return m + def ensure_fromlist(m, fromlist, recursive=0): """ Return the real modules list to be imported """ @@ -123,10 +134,16 @@ def ensure_fromlist(m, fromlist, recursive=0): pass else: l.extend(ensure_fromlist(m, all, 1)) - else: + elif hasattr(m,sub): submod=getattr(m,sub) if type(submod) == type(sys): l.append(("%s.%s" % (m.__name__, sub),submod)) + else: + subname="%s.%s" % (m.__name__, sub) + submod = import_module(sub, subname, m) + if not submod: + raise ImportError, "No module named " + subname + l.append((subname,submod)) return l def import_hook(name, globals=None, locals=None, fromlist=None): -- 2.39.2