]> jfr.im git - yt-dlp.git/blobdiff - youtube_dlc/compat.py
Add --write-*-link by h-h-h-h
[yt-dlp.git] / youtube_dlc / compat.py
index 1cf7efed615af3a4ec5bcdfe084ff0bf197b8b3c..4a69b098fb460ec8fe36d9c0b53e09065ab00a78 100644 (file)
 except ImportError:  # Python 2
     import urllib as compat_urllib_parse
 
+try:
+    import urllib.parse as compat_urlparse
+except ImportError:  # Python 2
+    import urlparse as compat_urlparse
+
 try:
     from urllib.parse import urlparse as compat_urllib_parse_urlparse
 except ImportError:  # Python 2
     from urlparse import urlparse as compat_urllib_parse_urlparse
 
 try:
-    import urllib.parse as compat_urlparse
+    from urllib.parse import urlunparse as compat_urllib_parse_urlunparse
 except ImportError:  # Python 2
-    import urlparse as compat_urlparse
+    from urlparse import urlunparse as compat_urllib_parse_urlunparse
 
 try:
     import urllib.response as compat_urllib_response
@@ -2345,7 +2350,7 @@ def __init__(self, version, name, value, *args, **kwargs):
 
         # HTMLParseError has been deprecated in Python 3.3 and removed in
         # Python 3.5. Introducing dummy exception for Python >3.5 for compatible
-        # and uniform cross-version exceptiong handling
+        # and uniform cross-version exception handling
         class compat_HTMLParseError(Exception):
             pass
 
@@ -2365,6 +2370,20 @@ class compat_HTMLParseError(Exception):
 except NameError:
     compat_str = str
 
+try:
+    from urllib.parse import quote as compat_urllib_parse_quote
+    from urllib.parse import quote_plus as compat_urllib_parse_quote_plus
+except ImportError:  # Python 2
+    def compat_urllib_parse_quote(string, safe='/'):
+        return compat_urllib_parse.quote(
+            string.encode('utf-8'),
+            str(safe))
+
+    def compat_urllib_parse_quote_plus(string, safe=''):
+        return compat_urllib_parse.quote_plus(
+            string.encode('utf-8'),
+            str(safe))
+
 try:
     from urllib.parse import unquote_to_bytes as compat_urllib_parse_unquote_to_bytes
     from urllib.parse import unquote as compat_urllib_parse_unquote
@@ -3033,11 +3052,14 @@ def compat_ctypes_WINFUNCTYPE(*args, **kwargs):
     'compat_tokenize_tokenize',
     'compat_urllib_error',
     'compat_urllib_parse',
+    'compat_urllib_parse_quote',
+    'compat_urllib_parse_quote_plus',
     'compat_urllib_parse_unquote',
     'compat_urllib_parse_unquote_plus',
     'compat_urllib_parse_unquote_to_bytes',
     'compat_urllib_parse_urlencode',
     'compat_urllib_parse_urlparse',
+    'compat_urllib_parse_urlunparse',
     'compat_urllib_request',
     'compat_urllib_request_DataHandler',
     'compat_urllib_response',