diff options
author | Guido van Rossum <guido@python.org> | 1998-03-26 21:13:24 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-03-26 21:13:24 (GMT) |
commit | 45e2fbc2e70ef28b1f0327207f33dab3a4e825c5 (patch) | |
tree | 24cafdb6ffb07170188292a02440935291327cde /Lib/knee.py | |
parent | 9ea7024754f0e42d7fc70fd1c8f6f6cfbf7e1cf0 (diff) | |
download | cpython-45e2fbc2e70ef28b1f0327207f33dab3a4e825c5.zip cpython-45e2fbc2e70ef28b1f0327207f33dab3a4e825c5.tar.gz cpython-45e2fbc2e70ef28b1f0327207f33dab3a4e825c5.tar.bz2 |
Mass check-in after untabifying all files that need it.
Diffstat (limited to 'Lib/knee.py')
-rw-r--r-- | Lib/knee.py | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/Lib/knee.py b/Lib/knee.py index 2473f9b..95c3c23 100644 --- a/Lib/knee.py +++ b/Lib/knee.py @@ -16,93 +16,93 @@ def import_hook(name, globals=None, locals=None, fromlist=None): q, tail = find_head_package(parent, name) m = load_tail(q, tail) if not fromlist: - return q + return q if hasattr(m, "__path__"): - ensure_fromlist(m, fromlist) + ensure_fromlist(m, fromlist) return m def determine_parent(globals): if not globals or not globals.has_key("__name__"): - return None + return None pname = globals['__name__'] if globals.has_key("__path__"): - parent = sys.modules[pname] - assert globals is parent.__dict__ - return parent + parent = sys.modules[pname] + assert globals is parent.__dict__ + return parent if '.' in pname: - i = string.rfind(pname, '.') - pname = pname[:i] - parent = sys.modules[pname] - assert parent.__name__ == pname - return parent + i = string.rfind(pname, '.') + pname = pname[:i] + parent = sys.modules[pname] + assert parent.__name__ == pname + return parent return None def find_head_package(parent, name): if '.' in name: - i = string.find(name, '.') - head = name[:i] - tail = name[i+1:] + i = string.find(name, '.') + head = name[:i] + tail = name[i+1:] else: - head = name - tail = "" + head = name + tail = "" if parent: - qname = "%s.%s" % (parent.__name__, head) + qname = "%s.%s" % (parent.__name__, head) else: - qname = head + qname = head q = import_module(head, qname, parent) if q: return q, tail if parent: - qname = head - parent = None - q = import_module(head, qname, parent) - if q: return q, tail + qname = head + parent = None + q = import_module(head, qname, parent) + if q: return q, tail raise ImportError, "No module named " + qname def load_tail(q, tail): m = q while tail: - i = string.find(tail, '.') - if i < 0: i = len(tail) - head, tail = tail[:i], tail[i+1:] - mname = "%s.%s" % (m.__name__, head) - m = import_module(head, mname, m) - if not m: - raise ImportError, "No module named " + mname + i = string.find(tail, '.') + if i < 0: i = len(tail) + head, tail = tail[:i], tail[i+1:] + mname = "%s.%s" % (m.__name__, head) + m = import_module(head, mname, m) + if not m: + raise ImportError, "No module named " + mname return m def ensure_fromlist(m, fromlist, recursive=0): for sub in fromlist: - if sub == "*": - if not recursive: - try: - all = m.__all__ - except AttributeError: - pass - else: - ensure_fromlist(m, all, 1) - continue - if sub != "*" and not hasattr(m, sub): - subname = "%s.%s" % (m.__name__, sub) - submod = import_module(sub, subname, m) - if not submod: - raise ImportError, "No module named " + subname + if sub == "*": + if not recursive: + try: + all = m.__all__ + except AttributeError: + pass + else: + ensure_fromlist(m, all, 1) + continue + if sub != "*" and not hasattr(m, sub): + subname = "%s.%s" % (m.__name__, sub) + submod = import_module(sub, subname, m) + if not submod: + raise ImportError, "No module named " + subname def import_module(partname, fqname, parent): try: - return sys.modules[fqname] + return sys.modules[fqname] except KeyError: - pass + pass try: - fp, pathname, stuff = imp.find_module(partname, - parent and parent.__path__) + fp, pathname, stuff = imp.find_module(partname, + parent and parent.__path__) except ImportError: - return None + return None try: - m = imp.load_module(fqname, fp, pathname, stuff) + m = imp.load_module(fqname, fp, pathname, stuff) finally: - if fp: fp.close() + if fp: fp.close() if parent: - setattr(parent, partname, m) + setattr(parent, partname, m) return m @@ -110,7 +110,7 @@ def import_module(partname, fqname, parent): def reload_hook(module): name = module.__name__ if '.' not in name: - return import_module(name, name, None) + return import_module(name, name, None) i = string.rfind(name, '.') pname = name[:i] parent = sys.modules[pname] |