]> git.phdru.name Git - m_lib.git/blob - m_lib/lazy/imports.py
Remove wrong copyright lines, fix module docstrings
[m_lib.git] / m_lib / lazy / imports.py
1 """Lazy imoport - import the module upon first request"""
2
3
4 try:
5    from mx.Misc import LazyModule
6
7 except ImportError:
8
9    class LazyModule:
10       def __init__(self, module_name, locals, globals=None):
11          self.module = None
12          self.module_name = module_name
13          self.locals = locals
14          if globals is None:
15             globals = locals
16          self.globals = globals
17
18       def __getattr__(self, attr):
19          if self.module is None:
20             self.module = module = __import__(self.module_name, self.globals, self.locals)
21          else:
22             module = self.module
23          return getattr(module, attr)