mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-07 18:15:46 +01:00
Removed unused imports and functions from poliglote urllib
This commit is contained in:
@@ -1,22 +1,17 @@
|
|||||||
from urllib.request import (build_opener, getproxies, install_opener,
|
import urllib.parse
|
||||||
HTTPBasicAuthHandler, HTTPCookieProcessor, HTTPDigestAuthHandler,
|
|
||||||
url2pathname, urlopen, Request)
|
|
||||||
from urllib.parse import (parse_qs, quote, unquote as uq, quote_plus, urldefrag,
|
|
||||||
urlencode, urljoin, urlparse, urlunparse, urlsplit, urlunsplit)
|
|
||||||
from urllib.error import HTTPError, URLError
|
|
||||||
|
|
||||||
|
|
||||||
def unquote(x, encoding='utf-8', errors='replace'):
|
def unquote(x, encoding='utf-8', errors='replace'):
|
||||||
|
# TODO(gryf): this works like that: if x is a binary, convert it to
|
||||||
|
# string using encoding and make unquote. After that make it binary again.
|
||||||
|
# If x is string, just pass it to the unquote.
|
||||||
|
# This approach is mostly used within lxml etree strings, which suppose to
|
||||||
|
# be binary because of its inner representation. I'm wondering, if
|
||||||
|
# xml.etree could be used instead - to be checked.
|
||||||
binary = isinstance(x, bytes)
|
binary = isinstance(x, bytes)
|
||||||
if binary:
|
if binary:
|
||||||
x = x.decode(encoding, errors)
|
x = x.decode(encoding, errors)
|
||||||
ans = uq(x, encoding, errors)
|
ans = urllib.parse.unquote(x, encoding, errors)
|
||||||
if binary:
|
if binary:
|
||||||
ans = ans.encode(encoding, errors)
|
ans = ans.encode(encoding, errors)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def unquote_plus(x, encoding='utf-8', errors='replace'):
|
|
||||||
q, repl = (b'+', b' ') if isinstance(x, bytes) else ('+', ' ')
|
|
||||||
x = x.replace(q, repl)
|
|
||||||
return unquote(x, encoding=encoding, errors=errors)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user