Show More
@@ -69,6 +69,7 b' class _demandmod(object):' | |||
|
69 | 69 | Specify 1 as 'level' argument at construction, to import module |
|
70 | 70 | relatively. |
|
71 | 71 | """ |
|
72 | ||
|
72 | 73 | def __init__(self, name, globals, locals, level): |
|
73 | 74 | if '.' in name: |
|
74 | 75 | head, rest = name.split('.', 1) |
@@ -79,6 +80,7 b' class _demandmod(object):' | |||
|
79 | 80 | object.__setattr__(self, r"_data", |
|
80 | 81 | (head, globals, locals, after, level, set())) |
|
81 | 82 | object.__setattr__(self, r"_module", None) |
|
83 | ||
|
82 | 84 | def _extend(self, name): |
|
83 | 85 | """add to the list of submodules to load""" |
|
84 | 86 | self._data[3].append(name) |
@@ -144,13 +146,16 b' class _demandmod(object):' | |||
|
144 | 146 | if self._module: |
|
145 | 147 | return "<proxied module '%s'>" % self._data[0] |
|
146 | 148 | return "<unloaded module '%s'>" % self._data[0] |
|
149 | ||
|
147 | 150 | def __call__(self, *args, **kwargs): |
|
148 | 151 | raise TypeError("%s object is not callable" % repr(self)) |
|
152 | ||
|
149 | 153 | def __getattribute__(self, attr): |
|
150 | 154 | if attr in ('_data', '_extend', '_load', '_module', '_addref'): |
|
151 | 155 | return object.__getattribute__(self, attr) |
|
152 | 156 | self._load() |
|
153 | 157 | return getattr(self._module, attr) |
|
158 | ||
|
154 | 159 | def __setattr__(self, attr, val): |
|
155 | 160 | self._load() |
|
156 | 161 | setattr(self._module, attr, val) |
General Comments 0
You need to be logged in to leave comments.
Login now