1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-16 23:03:32 +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

@@ -2,12 +2,15 @@
Provides abstraction for metadata reading.writing from a variety of ebook
formats.
"""
import os, sys, re
import os
import re
import sys
import urllib.parse
from ebook_converter import relpath, guess_type, prints, force_unicode
from ebook_converter.utils.config_base import tweaks
from ebook_converter.polyglot.builtins import codepoint_to_chr, unicode_type, getcwd, iteritems, itervalues, as_unicode
from ebook_converter.polyglot.urllib import quote, unquote, urlparse
from ebook_converter.polyglot.urllib import unquote
__license__ = 'GPL v3'
@@ -241,7 +244,7 @@ class Resource(object):
path = path.decode(sys.getfilesystemencoding())
self.path = path
else:
url = urlparse(href_or_path)
url = urllib.parse.urlparse(href_or_path)
if url[0] not in ('', 'file'):
self._href = href_or_path
else:
@@ -268,7 +271,7 @@ class Resource(object):
if self.path is None:
return self._href
f = self.fragment.encode('utf-8') if isinstance(self.fragment, unicode_type) else self.fragment
frag = '#'+as_unicode(quote(f)) if self.fragment else ''
frag = '#'+as_unicode(urllib.parse.quote(f)) if self.fragment else ''
if self.path == basedir:
return ''+frag
try:
@@ -277,7 +280,7 @@ class Resource(object):
rpath = self.path
if isinstance(rpath, unicode_type):
rpath = rpath.encode('utf-8')
return as_unicode(quote(rpath.replace(os.sep, '/')))+frag
return as_unicode(urllib.parse.quote(rpath.replace(os.sep, '/')))+frag
def set_basedir(self, path):
self._basedir = path

View File

@@ -1,7 +1,17 @@
"""
lxml based OPF parser.
"""
import re, sys, unittest, functools, os, uuid, glob, io, json, copy
import copy
import functools
import glob
import io
import json
import os
import re
import sys
import unittest
import urllib.parse
import uuid
from lxml import etree
@@ -18,7 +28,7 @@ from ebook_converter.utils.cleantext import clean_ascii_chars, clean_xml_chars
from ebook_converter.utils.config import tweaks
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from ebook_converter.polyglot.builtins import iteritems, unicode_type, getcwd
from ebook_converter.polyglot.urllib import unquote, urlparse
from ebook_converter.polyglot.urllib import unquote
__license__ = 'GPL v3'
@@ -76,7 +86,7 @@ class Resource(object): # {{{
self.path = path
else:
href_or_path = href_or_path
url = urlparse(href_or_path)
url = urllib.parse.urlparse(href_or_path)
if url[0] not in ('', 'file'):
self._href = href_or_path
else:

View File

@@ -1,5 +1,9 @@
import os, glob, re, functools
from collections import Counter
import collections
import functools
import glob
import os
import re
import urllib.parse
from lxml import etree
from lxml.builder import ElementMaker
@@ -9,7 +13,7 @@ from ebook_converter.ebooks.chardet import xml_to_unicode
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from ebook_converter.utils.cleantext import clean_xml_chars
from ebook_converter.polyglot.builtins import unicode_type, getcwd
from ebook_converter.polyglot.urllib import unquote, urlparse
from ebook_converter.polyglot.urllib import unquote
__license__ = 'GPL v3'
@@ -30,7 +34,7 @@ def parse_html_toc(data):
data = xml_to_unicode(data, strip_encoding_pats=True, resolve_entities=True)[0]
root = parse(clean_xml_chars(data), maybe_xhtml=True, keep_doctype=False, sanitize_names=True)
for a in root.xpath('//*[@href and local-name()="a"]'):
purl = urlparse(unquote(a.get('href')))
purl = urllib.parse.urlparse(unquote(a.get('href')))
href, fragment = purl[2], purl[5]
if not fragment:
fragment = None
@@ -142,7 +146,7 @@ class TOC(list):
if toc is not None:
if toc.lower() not in ('ncx', 'ncxtoc'):
toc = urlparse(unquote(toc))[2]
toc = urllib.parse.urlparse(unquote(toc))[2]
toc = toc.replace('/', os.sep)
if not os.path.isabs(toc):
toc = os.path.join(self.base_path, toc)
@@ -209,7 +213,7 @@ class TOC(list):
if content and text:
content = content[0]
# if get_attr(content, attr='src'):
purl = urlparse(content.get('src'))
purl = urllib.parse.urlparse(content.get('src'))
href, fragment = unquote(purl[2]), unquote(purl[5])
nd = dest.add_item(href, fragment, text)
nd.play_order = play_order
@@ -253,7 +257,7 @@ class TOC(list):
navmap = E.navMap()
root.append(navmap)
root.set('{http://www.w3.org/XML/1998/namespace}lang', 'en')
c = Counter()
c = collections.Counter()
def navpoint(parent, np):
text = np.text