2
0
Эх сурвалжийг харах

[utils] Support optional `safe` argument for `escape_rfc3986()`

dirkf 5 сар өмнө
parent
commit
2190e89260

+ 6 - 2
youtube_dl/utils.py

@@ -4204,12 +4204,16 @@ def lowercase_escape(s):
         s)
         s)
 
 
 
 
-def escape_rfc3986(s):
+def escape_rfc3986(s, safe=None):
     """Escape non-ASCII characters as suggested by RFC 3986"""
     """Escape non-ASCII characters as suggested by RFC 3986"""
     if sys.version_info < (3, 0):
     if sys.version_info < (3, 0):
         s = _encode_compat_str(s, 'utf-8')
         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
     # 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):
 def escape_url(url):