1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-09 11:05:45 +01:00

Removing is_py3 method and duplicated by urllib.

This commit is contained in:
2020-04-19 21:22:24 +02:00
parent b66cbd2c1e
commit ef7e2b10be
35 changed files with 267 additions and 254 deletions

View File

@@ -1,8 +0,0 @@
from ebook_converter.polyglot.builtins import is_py3
if is_py3:
from functools import lru_cache
else:
from backports.functools_lru_cache import lru_cache
lru_cache

View File

@@ -1,10 +0,0 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
from ebook_converter.polyglot.builtins import is_py3
if is_py3:
from html.entities import name2codepoint
else:
from htmlentitydefs import name2codepoint

View File

@@ -1,44 +1,19 @@
from ebook_converter.polyglot.builtins import is_py3
from urllib.request import (build_opener, getproxies, install_opener,
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
if is_py3:
from urllib.request import (build_opener, getproxies, install_opener, # noqa
HTTPBasicAuthHandler, HTTPCookieProcessor, HTTPDigestAuthHandler, # noqa
url2pathname, urlopen, Request) # noqa
from urllib.parse import (parse_qs, quote, unquote as uq, quote_plus, urldefrag, # noqa
urlencode, urljoin, urlparse, urlunparse, urlsplit, urlunsplit) # noqa
from urllib.error import HTTPError, URLError # noqa
def unquote(x, encoding='utf-8', errors='replace'):
binary = isinstance(x, bytes)
if binary:
x = x.decode(encoding, errors)
ans = uq(x, encoding, errors)
if binary:
ans = ans.encode(encoding, errors)
return ans
else:
from urllib import (getproxies, quote, unquote as uq, quote_plus, url2pathname, # noqa
urlencode) # noqa
from urllib2 import (build_opener, install_opener, HTTPBasicAuthHandler, # noqa
HTTPCookieProcessor, HTTPDigestAuthHandler, HTTPError, URLError, # noqa
urlopen, Request) # noqa
from urlparse import (parse_qs, urldefrag, urljoin, urlparse, urlunparse, # noqa
urlsplit, urlunsplit) # noqa
def unquote(x, encoding='utf-8', errors='replace'):
# unquote must run on a bytestring and will return a bytestring
# If it runs on a unicode object, it returns a double encoded unicode
# string: unquote(u'%C3%A4') != unquote(b'%C3%A4').decode('utf-8')
# and the latter is correct
binary = isinstance(x, bytes)
if not binary:
x = x.encode(encoding, errors)
ans = uq(x)
if not binary:
ans = ans.decode(encoding, errors)
return ans
def unquote(x, encoding='utf-8', errors='replace'):
binary = isinstance(x, bytes)
if binary:
x = x.decode(encoding, errors)
ans = uq(x, encoding, errors)
if binary:
ans = ans.encode(encoding, errors)
return ans
def unquote_plus(x, encoding='utf-8', errors='replace'):