X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=bin%2Fwget-download;h=a851395a6b36aa8d610c146663beea21712ba78c;hb=a9641b9731213a7d70247dcc46dcfc1c846df03b;hp=dbd6ef5bfd4cf13390630223ac3f093740ccd86a;hpb=3fdf2f7baaa3a67880de95948d6ee76bc698fbc9;p=dotfiles.git diff --git a/bin/wget-download b/bin/wget-download index dbd6ef5..a851395 100755 --- a/bin/wget-download +++ b/bin/wget-download @@ -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 = []