1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-28 01:33:45 +02: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
@@ -11,6 +11,7 @@ import uuid
from collections import defaultdict
from io import BytesIO
from itertools import count
import urllib.parse
from css_parser import getUrls, replaceUrls
@@ -49,7 +50,6 @@ from ebook_converter.utils.logging import default_log
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter.polyglot.builtins import iteritems, unicode_type
from ebook_converter.polyglot.urllib import urlparse
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
@@ -107,7 +107,7 @@ def name_to_href(name, root, base=None, quote=urlquote):
def href_to_name(href, root, base=None):
base = root if base is None else os.path.dirname(name_to_abspath(base, root))
try:
purl = urlparse(href)
purl = urllib.parse.urlparse(href)
except ValueError:
return None
if purl.scheme or not purl.path:
+5 -5
View File
@@ -2,13 +2,13 @@ import codecs, shutil, os, posixpath
from ebook_converter.polyglot.builtins import iteritems, itervalues
from functools import partial
from collections import Counter, defaultdict
import urllib.parse
from ebook_converter import sanitize_file_name
from ebook_converter.ebooks.chardet import strip_encoding_declarations
from ebook_converter.ebooks.oeb.base import css_text
from ebook_converter.ebooks.oeb.polish.css import iter_declarations, remove_property_value
from ebook_converter.ebooks.oeb.polish.utils import extract
from ebook_converter.polyglot.urllib import urlparse, urlunparse
__license__ = 'GPL v3'
@@ -38,7 +38,7 @@ class LinkReplacer(object):
nname = self.link_map.get(name, None)
if not nname:
return url
purl = urlparse(url)
purl = urllib.parse.urlparse(url)
href = self.container.name_to_href(nname, self.base)
if purl.fragment:
nfrag = self.frag_map(name, purl.fragment)
@@ -68,12 +68,12 @@ class IdReplacer(object):
id_map = self.id_map.get(name)
if id_map is None:
return url
purl = urlparse(url)
purl = urllib.parse.urlparse(url)
nfrag = id_map.get(purl.fragment)
if nfrag is None:
return url
purl = purl._replace(fragment=nfrag)
href = urlunparse(purl)
href = urllib.parse.urlunparse(purl)
if href != url:
self.replaced = True
return href
@@ -89,7 +89,7 @@ class LinkRebaser(object):
def __call__(self, url):
if url and url.startswith('#'):
return url
purl = urlparse(url)
purl = urllib.parse.urlparse(url)
frag = purl.fragment
name = self.container.href_to_name(url, self.old_name)
if not name:
+4 -4
View File
@@ -1,12 +1,12 @@
import copy, os, re
from ebook_converter.polyglot.builtins import string_or_bytes
import urllib.parse
from ebook_converter.ebooks.oeb.base import barename, XPNSMAP, XPath, OPF, XHTML, OEB_DOCS
from ebook_converter.ebooks.oeb.polish.errors import MalformedMarkup
from ebook_converter.ebooks.oeb.polish.toc import node_from_loc
from ebook_converter.ebooks.oeb.polish.replace import LinkRebaser
from ebook_converter.polyglot.builtins import iteritems, unicode_type
from ebook_converter.polyglot.urllib import urlparse
__license__ = 'GPL v3'
@@ -160,7 +160,7 @@ class SplitLinkReplacer(object):
name = self.container.href_to_name(url, self.base)
if name != self.top_name:
return url
purl = urlparse(url)
purl = urllib.parse.urlparse(url)
if purl.fragment and purl.fragment in self.bottom_anchors:
url = self.container.name_to_href(self.bottom_name, self.base) + '#' + purl.fragment
self.replaced = True
@@ -225,7 +225,7 @@ def split(container, name, loc_or_xpath, before=True, totals=None):
else:
fname = container.href_to_name(url, name)
if fname == name:
purl = urlparse(url)
purl = urllib.parse.urlparse(url)
if purl.fragment in anchors_in_top:
if r is root2:
a.set('href', '%s#%s' % (container.name_to_href(name, bottom_name), purl.fragment))
@@ -310,7 +310,7 @@ class MergeLinkReplacer(object):
amap = self.anchor_map.get(name, None)
if amap is None:
return url
purl = urlparse(url)
purl = urllib.parse.urlparse(url)
frag = purl.fragment or ''
frag = amap.get(frag, frag)
url = self.container.name_to_href(self.master, self.base) + '#' + frag
+4 -4
View File
@@ -3,6 +3,7 @@ from collections import Counter, OrderedDict
from functools import partial
from operator import itemgetter
import pkg_resources
import urllib.parse
from lxml import etree
from lxml.builder import ElementMaker
@@ -16,7 +17,6 @@ from ebook_converter.ebooks.oeb.polish.opf import set_guide_item, get_book_langu
from ebook_converter.ebooks.oeb.polish.pretty import pretty_html_tree
from ebook_converter.utils.localization import get_lang, canonicalize_lang, lang_as_iso639_1
from ebook_converter.polyglot.builtins import iteritems, unicode_type
from ebook_converter.polyglot.urllib import urlparse
__license__ = 'GPL v3'
@@ -150,7 +150,7 @@ def add_from_navpoint(container, navpoint, parent, ncx_name):
href = content.get('src', None)
if href:
dest = container.href_to_name(href, base=ncx_name)
frag = urlparse(href).fragment or None
frag = urllib.parse.urlparse(href).fragment or None
return parent.add(text or None, dest or None, frag or None)
@@ -183,7 +183,7 @@ def parse_ncx(container, ncx_name):
href = pt.xpath('descendant::*[calibre:lower-case(local-name()) = "content"]/@src')
if href:
dest = container.href_to_name(href[0], base=ncx_name)
frag = urlparse(href[0]).fragment or None
frag = urllib.parse.urlparse(href[0]).fragment or None
toc_root.page_list.append({'dest': dest, 'pagenum': pagenum, 'frag': frag})
return toc_root
@@ -195,7 +195,7 @@ def add_from_li(container, li, parent, nav_name):
href = x.get('href')
if href:
dest = nav_name if href.startswith('#') else container.href_to_name(href, base=nav_name)
frag = urlparse(href).fragment or None
frag = urllib.parse.urlparse(href).fragment or None
break
return parent.add(text or None, dest or None, frag or None)