]> git.phdru.name Git - dotfiles.git/blobdiff - bin/wget-download
Fix(Py3): Use `urllib.parse.urlsplit()`
[dotfiles.git] / bin / wget-download
index dbd6ef5bfd4cf13390630223ac3f093740ccd86a..a851395a6b36aa8d610c146663beea21712ba78c 100755 (executable)
@@ -1,22 +1,17 @@
 #! /usr/bin/env python3
 
-try:
-    from urllib.parse import parse_qsl, urlencode, \
-        quote, quote_plus, unquote, unquote_plus, \
-        splittype, splithost, splituser, splitpasswd, \
-        splitport, splittag, splitquery
-except ImportError:
-    from cgi import parse_qsl
-    from urllib import urlencode, quote, quote_plus, unquote, unquote_plus, \
-        splittype, splithost, splituser, splitpasswd, \
-        splitport, splittag, splitquery
 from getopt import getopt, GetoptError
-import os, posixpath
+from urllib.parse import urlsplit, parse_qsl, quote, quote_plus, urlencode
+import os
+import posixpath
 import sys
 from m_lib.defenc import default_encoding
 
+
 def usage():
-    sys.exit('Usage: %s [-e|--encoding=encoding] [-n|--newwin|-t|--tab] URL' % sys.argv[0])
+    sys.exit('Usage: %s [-e|--encoding=encoding] [-n|--newwin|-t|--tab] URL'
+             % sys.argv[0])
+
 
 try:
     options, arguments = getopt(sys.argv[1:], 'e:', ['encoding='])
@@ -36,19 +31,13 @@ if not encoding:
     encoding = default_encoding
 
 url = arguments[0]
-protocol, request = splittype(url)
-user, password, port = None, None, None
-host, path = splithost(request)
-if host:
-    user, host = splituser(host)
-    if user:
-        user, password = splitpasswd(user)
-    host, port = splitport(host)
-    if port: port = int(port)
-path, tag = splittag(path)
-path, query = splitquery(path)
-path = unquote(path)
-if tag: tag = unquote_plus(tag)
+
+split_results = urlsplit(url)
+protocol, netloc, path, query, tag = split_results
+user = split_results.username
+password = split_results.password
+host = split_results.hostname
+port = split_results.port
 
 if query:
     qlist = []