diff --git a/hgdemandimport/demandimportpy2.py b/hgdemandimport/demandimportpy2.py index 8472333744347bd802f5652597e88807413016ab_aGdkZW1hbmRpbXBvcnQvZGVtYW5kaW1wb3J0cHkyLnB5..63365e9621d6c45f778f587d3a10d90f9672947a_aGdkZW1hbmRpbXBvcnQvZGVtYW5kaW1wb3J0cHkyLnB5 100644 --- a/hgdemandimport/demandimportpy2.py +++ b/hgdemandimport/demandimportpy2.py @@ -69,6 +69,7 @@ Specify 1 as 'level' argument at construction, to import module relatively. """ + def __init__(self, name, globals, locals, level): if '.' in name: head, rest = name.split('.', 1) @@ -79,6 +80,7 @@ object.__setattr__(self, r"_data", (head, globals, locals, after, level, set())) object.__setattr__(self, r"_module", None) + def _extend(self, name): """add to the list of submodules to load""" self._data[3].append(name) @@ -144,5 +146,6 @@ if self._module: return "<proxied module '%s'>" % self._data[0] return "<unloaded module '%s'>" % self._data[0] + def __call__(self, *args, **kwargs): raise TypeError("%s object is not callable" % repr(self)) @@ -147,7 +150,8 @@ def __call__(self, *args, **kwargs): raise TypeError("%s object is not callable" % repr(self)) + def __getattribute__(self, attr): if attr in ('_data', '_extend', '_load', '_module', '_addref'): return object.__getattribute__(self, attr) self._load() return getattr(self._module, attr) @@ -149,8 +153,9 @@ def __getattribute__(self, attr): if attr in ('_data', '_extend', '_load', '_module', '_addref'): return object.__getattribute__(self, attr) self._load() return getattr(self._module, attr) + def __setattr__(self, attr, val): self._load() setattr(self._module, attr, val)