aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/compat/compat_utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-06-24 15:40:13 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-06-25 00:08:52 +0530
commit3c5386cd711a5a0480a0b8d72e9df5007b10ac92 (patch)
treeacc00b854ed5766d8d81defc7a4e4d56e82c67b7 /yt_dlp/compat/compat_utils.py
parentbc401608830ba34831c31b74eb5661114bf284e7 (diff)
downloadhypervideo-pre-3c5386cd711a5a0480a0b8d72e9df5007b10ac92.tar.lz
hypervideo-pre-3c5386cd711a5a0480a0b8d72e9df5007b10ac92.tar.xz
hypervideo-pre-3c5386cd711a5a0480a0b8d72e9df5007b10ac92.zip
[compat] Fix `compat.WINDOWS_VT_MODE`
Diffstat (limited to 'yt_dlp/compat/compat_utils.py')
-rw-r--r--yt_dlp/compat/compat_utils.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/yt_dlp/compat/compat_utils.py b/yt_dlp/compat/compat_utils.py
index 8da4fcc0a..79e253056 100644
--- a/yt_dlp/compat/compat_utils.py
+++ b/yt_dlp/compat/compat_utils.py
@@ -31,7 +31,7 @@ def _is_package(module):
return True
-def passthrough_module(parent, child, *, callback=lambda _: None):
+def passthrough_module(parent, child, allowed_attributes=None, *, callback=lambda _: None):
parent_module = importlib.import_module(parent)
child_module = None # Import child module only as needed
@@ -41,22 +41,30 @@ def passthrough_module(parent, child, *, callback=lambda _: None):
with contextlib.suppress(ImportError):
return importlib.import_module(f'.{attr}', parent)
+ ret = self.__from_child(attr)
+ if ret is _NO_ATTRIBUTE:
+ raise AttributeError(f'module {parent} has no attribute {attr}')
+ callback(attr)
+ return ret
+
+ def __from_child(self, attr):
+ if allowed_attributes is None:
+ if attr.startswith('__') and attr.endswith('__'):
+ return _NO_ATTRIBUTE
+ elif attr not in allowed_attributes:
+ return _NO_ATTRIBUTE
+
nonlocal child_module
child_module = child_module or importlib.import_module(child, parent)
- ret = _NO_ATTRIBUTE
with contextlib.suppress(AttributeError):
- ret = getattr(child_module, attr)
+ return getattr(child_module, attr)
if _is_package(child_module):
with contextlib.suppress(ImportError):
- ret = importlib.import_module(f'.{attr}', child)
+ return importlib.import_module(f'.{attr}', child)
- if ret is _NO_ATTRIBUTE:
- raise AttributeError(f'module {parent} has no attribute {attr}')
-
- callback(attr)
- return ret
+ return _NO_ATTRIBUTE
# Python 3.6 does not have module level __getattr__
# https://peps.python.org/pep-0562/