]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
779822d9 JMF |
2 | import re |
3 | ||
4 | ||
5bc4a65e | 5 | class LazyLoadMetaClass(type): |
6 | def __getattr__(cls, name): | |
7 | return getattr(cls._get_real_class(), name) | |
8 | ||
9 | ||
10 | class LazyLoadExtractor(metaclass=LazyLoadMetaClass): | |
779822d9 | 11 | _module = None |
251ae04e | 12 | _WORKING = True |
779822d9 | 13 | |
5bc4a65e | 14 | @classmethod |
15 | def _get_real_class(cls): | |
16 | if '__real_class' not in cls.__dict__: | |
17 | mod = __import__(cls._module, fromlist=(cls.__name__,)) | |
18 | cls.__real_class = getattr(mod, cls.__name__) | |
19 | return cls.__real_class | |
20 | ||
8a5dc1c1 | 21 | def __new__(cls, *args, **kwargs): |
5bc4a65e | 22 | real_cls = cls._get_real_class() |
8a5dc1c1 JMF |
23 | instance = real_cls.__new__(real_cls) |
24 | instance.__init__(*args, **kwargs) | |
25 | return instance |