diff options
author | dirkf <fieldhouse@gmx.net> | 2025-04-07 16:00:11 +0100 |
---|---|---|
committer | dirkf <fieldhouse@gmx.net> | 2025-04-08 01:59:00 +0100 |
commit | 2190e892603d238e1a1fc40477bf30d131c22acc (patch) | |
tree | 4f24ac6f1fc7ae897e163c3d40ebd8fca06be7ed | |
parent | 7e136639dba8a6d0e966ccc41b3dd8231587c67b (diff) |
[utils] Support optional `safe` argument for `escape_rfc3986()`
-rw-r--r-- | youtube_dl/utils.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index ac1e78002..c4262936e 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -4204,12 +4204,16 @@ def lowercase_escape(s): s) -def escape_rfc3986(s): +def escape_rfc3986(s, safe=None): """Escape non-ASCII characters as suggested by RFC 3986""" if sys.version_info < (3, 0): s = _encode_compat_str(s, 'utf-8') + if safe is not None: + safe = _encode_compat_str(safe, 'utf-8') + if safe is None: + safe = b"%/;:@&=+$,!~*'()?#[]" # ensure unicode: after quoting, it can always be converted - return compat_str(compat_urllib_parse.quote(s, b"%/;:@&=+$,!~*'()?#[]")) + return compat_str(compat_urllib_parse.quote(s, safe)) def escape_url(url): |