]>
Commit | Line | Data |
---|---|---|
82d02080 | 1 | import importlib |
2 | import random | |
779822d9 JMF |
3 | import re |
4 | ||
24146491 | 5 | from ..utils import ( |
6 | age_restricted, | |
7 | bug_reports_message, | |
8 | classproperty, | |
9 | write_string, | |
10 | ) | |
e6f21b3d | 11 | |
779822d9 | 12 | |
5bc4a65e | 13 | class LazyLoadMetaClass(type): |
14 | def __getattr__(cls, name): | |
24146491 | 15 | # "_TESTS" bloat the lazy_extractors |
16 | if '_real_class' not in cls.__dict__ and name != 'get_testcases': | |
e6f21b3d | 17 | write_string( |
1d485a1a | 18 | 'WARNING: Falling back to normal extractor since lazy extractor ' |
82d02080 | 19 | f'{cls.__name__} does not have attribute {name}{bug_reports_message()}\n') |
20 | return getattr(cls.real_class, name) | |
5bc4a65e | 21 | |
22 | ||
23 | class LazyLoadExtractor(metaclass=LazyLoadMetaClass): | |
82d02080 | 24 | @classproperty |
25 | def real_class(cls): | |
e6f21b3d | 26 | if '_real_class' not in cls.__dict__: |
82d02080 | 27 | cls._real_class = getattr(importlib.import_module(cls._module), cls.__name__) |
e6f21b3d | 28 | return cls._real_class |
5bc4a65e | 29 | |
8a5dc1c1 | 30 | def __new__(cls, *args, **kwargs): |
82d02080 | 31 | instance = cls.real_class.__new__(cls.real_class) |
8a5dc1c1 JMF |
32 | instance.__init__(*args, **kwargs) |
33 | return instance |