3 from cgi import parse_qsl
4 from getopt import getopt, GetoptError
7 from m_lib.defenc import default_encoding
10 sys.exit('Usage: %s [-e|--encoding=encoding] [-n|--newwin|-t|--tab] URL' % sys.argv[0])
13 options, arguments = getopt(sys.argv[1:], 'e:', ['encoding='])
17 if len(arguments) != 1:
22 for option, value in options:
23 if option in ('-e', '--encoding'):
27 encoding = default_encoding
30 protocol, request = urllib.splittype(url)
31 user, password, port = None, None, None
32 host, path = urllib.splithost(request)
34 user, host = urllib.splituser(host)
36 user, password = urllib.splitpasswd(user)
37 host, port = urllib.splitport(host)
38 if port: port = int(port)
39 path, tag = urllib.splittag(path)
40 path, query = urllib.splitquery(path)
41 path = urllib.unquote(path)
45 for name, value in parse_qsl(query):
46 name = unicode(name, default_encoding).encode(encoding)
47 value = unicode(value, default_encoding).encode(encoding)
48 qlist.append((name, value))
50 url = protocol + "://"
52 url += urllib.quote(unicode(user, default_encoding).encode(encoding))
54 url += ':' + urllib.quote(unicode(password, default_encoding).encode(encoding))
57 url += host.decode(encoding).encode('idna')
61 if protocol == "file":
62 url += urllib.quote(path)
64 url += urllib.quote(unicode(path, default_encoding).encode(encoding))
66 # url += '?' + urllib.urlencode(qlist)
68 name = posixpath.basename(path)
69 os.system('exec wget-wrapper -O "%s" "%s"' % (name, url))