Show More
@@ -27,6 +27,8 b' These imports will not be delayed:' | |||
|
27 | 27 | import __builtin__ |
|
28 | 28 | _origimport = __import__ |
|
29 | 29 | |
|
30 | nothing = object() | |
|
31 | ||
|
30 | 32 | class _demandmod(object): |
|
31 | 33 | """module demand-loader and proxy""" |
|
32 | 34 | def __init__(self, name, globals, locals): |
@@ -50,7 +52,7 b' class _demandmod(object):' | |||
|
50 | 52 | h, t = p, None |
|
51 | 53 | if '.' in p: |
|
52 | 54 | h, t = p.split('.', 1) |
|
53 |
if |
|
|
55 | if getattr(mod, h, nothing) is nothing: | |
|
54 | 56 | setattr(mod, h, _demandmod(p, mod.__dict__, mod.__dict__)) |
|
55 | 57 | elif t: |
|
56 | 58 | subload(getattr(mod, h), t) |
@@ -109,12 +111,12 b' def _demandimport(name, globals=None, lo' | |||
|
109 | 111 | mod = _origimport(name, globals, locals) |
|
110 | 112 | # recurse down the module chain |
|
111 | 113 | for comp in name.split('.')[1:]: |
|
112 |
if |
|
|
114 | if getattr(mod, comp, nothing) is nothing: | |
|
113 | 115 | setattr(mod, comp, _demandmod(comp, mod.__dict__, mod.__dict__)) |
|
114 | 116 | mod = getattr(mod, comp) |
|
115 | 117 | for x in fromlist: |
|
116 | 118 | # set requested submodules for demand load |
|
117 |
if |
|
|
119 | if getattr(mod, x, nothing) is nothing: | |
|
118 | 120 | setattr(mod, x, _demandmod(x, mod.__dict__, locals)) |
|
119 | 121 | return mod |
|
120 | 122 | |
@@ -148,4 +150,3 b' def enable():' | |||
|
148 | 150 | def disable(): |
|
149 | 151 | "disable global demand-loading of modules" |
|
150 | 152 | __builtin__.__import__ = _origimport |
|
151 |
General Comments 0
You need to be logged in to leave comments.
Login now