aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/compat.py
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2024-04-21 23:42:08 +0100
committerdirkf <fieldhouse@gmx.net>2024-05-30 15:46:36 +0100
commit06da64ee51cd405b9392ba484cf7d3d31a88ee30 (patch)
tree9e52705c22131dea945bf015447d080faef778ba /youtube_dl/compat.py
parenta08f2b7e4567cdc50c0614ee0a4ffdff49b8b6e6 (diff)
[utils] Update traverse_obj() from yt-dlp
* remove `is_user_input` option per https://github.com/yt-dlp/yt-dlp/pull/8673 * support traversal of compat_xml_etree_ElementTree_Element per https://github.com/yt-dlp/yt-dlp/pull/8911 * allow un/branching using all and any per https://github.com/yt-dlp/yt-dlp/pull/9571 * support traversal of compat_cookies.Morsel and multiple types in `set()` keys per https://github.com/yt-dlp/yt-dlp/pull/9577 thx Grub4k for these * also, move traversal tests to a separate class * allow for unordered dicts in tests for Py<3.7
Diffstat (limited to 'youtube_dl/compat.py')
-rw-r--r--youtube_dl/compat.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py
index 53ff2a892..d5485c7e8 100644
--- a/youtube_dl/compat.py
+++ b/youtube_dl/compat.py
@@ -2719,8 +2719,14 @@ if sys.version_info < (2, 7):
if isinstance(xpath, compat_str):
xpath = xpath.encode('ascii')
return xpath
+
+ def compat_etree_iterfind(element, match):
+ for from_ in element.findall(match):
+ yield from_
+
else:
compat_xpath = lambda xpath: xpath
+ compat_etree_iterfind = lambda element, match: element.iterfind(match)
compat_os_name = os._name if os.name == 'java' else os.name
@@ -2955,7 +2961,7 @@ except ImportError:
return self
def __exit__(self, exc_type, exc_val, exc_tb):
- return exc_val is not None and isinstance(exc_val, self._exceptions or tuple())
+ return exc_type is not None and issubclass(exc_type, self._exceptions or tuple())
# subprocess.Popen context manager
@@ -3308,6 +3314,7 @@ __all__ = [
'compat_contextlib_suppress',
'compat_ctypes_WINFUNCTYPE',
'compat_etree_fromstring',
+ 'compat_etree_iterfind',
'compat_filter',
'compat_get_terminal_size',
'compat_getenv',