]> jfr.im git - yt-dlp.git/blob - devscripts/lazy_load_template.py
[docs] Improve manpage format (#2003)
[yt-dlp.git] / devscripts / lazy_load_template.py
1 # coding: utf-8
2 import re
3
4 from ..utils import bug_reports_message, write_string
5
6
7 class LazyLoadMetaClass(type):
8 def __getattr__(cls, name):
9 if '_real_class' not in cls.__dict__:
10 write_string(
11 f'WARNING: Falling back to normal extractor since lazy extractor '
12 f'{cls.__name__} does not have attribute {name}{bug_reports_message()}')
13 return getattr(cls._get_real_class(), name)
14
15
16 class LazyLoadExtractor(metaclass=LazyLoadMetaClass):
17 _module = None
18 _WORKING = True
19
20 @classmethod
21 def _get_real_class(cls):
22 if '_real_class' not in cls.__dict__:
23 mod = __import__(cls._module, fromlist=(cls.__name__,))
24 cls._real_class = getattr(mod, cls.__name__)
25 return cls._real_class
26
27 def __new__(cls, *args, **kwargs):
28 real_cls = cls._get_real_class()
29 instance = real_cls.__new__(real_cls)
30 instance.__init__(*args, **kwargs)
31 return instance