def import_submodule(mod, subname, fullname):
<EOL>global found_now<EOL>if fullname in found_now and fullname in sys.modules:<EOL><INDENT>m = sys.modules[fullname]<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>', fullname)<EOL>found_now[fullname] = <NUM_LIT:1><EOL>oldm = sys.modules.get(fullname, None)<EOL>if mod is None:<EOL><INDENT>path = None<EOL><DEDENT>elif hasattr(mod, '<STR_LIT>'):<EOL><INDENT>path = mod.__path__<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>try:<EOL><INDENT>with replace_import_hook(original_import):<EOL><INDENT>fp, filename, stuff = imp.find_module(subname, path)<EOL><DEDENT><DEDENT>except ImportError:<EOL><INDENT>return None<EOL><DEDENT>try:<EOL><INDENT>m = imp.load_module(fullname, fp, filename, stuff)<EOL><DEDENT>except:<EOL><INDENT>if oldm:<EOL><INDENT>sys.modules[fullname] = oldm<EOL><DEDENT>raise<EOL><DEDENT>finally:<EOL><INDENT>if fp: fp.close()<EOL><DEDENT>add_submodule(mod, m, fullname, subname)<EOL><DEDENT>return m<EOL>
m = import_submodule(mod, subname, fullname)