| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net> |
| 4 |
|
| 5 |
|
| 6 |
from urllib.request import (build_opener, getproxies, install_opener, # noqa |
| 7 |
HTTPBasicAuthHandler, HTTPCookieProcessor, HTTPDigestAuthHandler, # noqa |
| 8 |
url2pathname, urlopen, Request) # noqa |
| 9 |
from urllib.parse import (parse_qs, quote, unquote as uq, quote_plus, urldefrag, # noqa |
| 10 |
urlencode, urljoin, urlparse, urlunparse, urlsplit, urlunsplit) # noqa |
| 11 |
from urllib.error import HTTPError, URLError # noqa |
| 12 |
|
| 13 |
|
| 14 |
def unquote(x, encoding='utf-8', errors='replace'): |
| 15 |
binary = isinstance(x, bytes) |
| 16 |
if binary: |
| 17 |
x = x.decode(encoding, errors) |
| 18 |
ans = uq(x, encoding, errors) |
| 19 |
if binary: |
| 20 |
ans = ans.encode(encoding, errors) |
| 21 |
return ans |
| 22 |
|
| 23 |
|
| 24 |
def unquote_plus(x, encoding='utf-8', errors='replace'): |
| 25 |
q, repl = (b'+', b' ') if isinstance(x, bytes) else ('+', ' ') |
| 26 |
x = x.replace(q, repl) |
| 27 |
return unquote(x, encoding=encoding, errors=errors) |