1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-05-01 19:30:52 +02:00

Removed polyglots unicode_type usage

This commit is contained in:
2020-04-20 19:25:28 +02:00
parent ef7e2b10be
commit 128705f258
130 changed files with 657 additions and 716 deletions
@@ -49,7 +49,7 @@ from ebook_converter.utils.ipc.simple_worker import WorkerError, fork_job
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.builtins import iteritems
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
@@ -163,7 +163,7 @@ class ContainerBase(object): # {{{
"""
def fix_data(d):
return d.replace('\r\n', '\n').replace('\r', '\n')
if isinstance(data, unicode_type):
if isinstance(data, str):
return fix_data(data)
bom_enc = None
if data[:4] in {b'\0\0\xfe\xff', b'\xff\xfe\0\0'}:
@@ -681,7 +681,7 @@ class Container(ContainerBase): # {{{
''' The names of all manifest items whose media-type matches predicate.
`predicate` can be a set, a list, a string or a function taking a single
argument, which will be called with the media-type. '''
if isinstance(predicate, unicode_type):
if isinstance(predicate, str):
predicate = predicate.__eq__
elif hasattr(predicate, '__contains__'):
predicate = predicate.__contains__
+3 -3
View File
@@ -10,7 +10,7 @@ from ebook_converter.ebooks.oeb.normalize_css import normalize_filter_css, norma
from ebook_converter.ebooks.oeb.polish.pretty import pretty_script_or_style, pretty_xml_tree, serialize
from ebook_converter.utils.icu import numeric_sort_key
from ebook_converter.css_selectors import Select, SelectorError
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
from ebook_converter.polyglot.builtins import iteritems, itervalues
__license__ = 'GPL v3'
@@ -342,10 +342,10 @@ def sort_sheet(container, sheet_or_text):
''' Sort the rules in a stylesheet. Note that in the general case this can
change the effective styles, but for most common sheets, it should be safe.
'''
sheet = container.parse_css(sheet_or_text) if isinstance(sheet_or_text, unicode_type) else sheet_or_text
sheet = container.parse_css(sheet_or_text) if isinstance(sheet_or_text, str) else sheet_or_text
def text_sort_key(x):
return numeric_sort_key(unicode_type(x or ''))
return numeric_sort_key(str(x or ''))
def selector_sort_key(x):
return (x.specificity, text_sort_key(x.selectorText))
+1 -2
View File
@@ -7,7 +7,6 @@ from ebook_converter import xml_replace_entities
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from ebook_converter.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
from ebook_converter.utils.cleantext import clean_xml_chars
from ebook_converter.polyglot.builtins import unicode_type
__license__ = 'GPL v3'
@@ -81,7 +80,7 @@ def parse(raw, decoder=None, log=None, line_numbers=True, linenumber_attribute=N
if linenumber_attribute:
for elem in ans.iter(LxmlElement):
if elem.sourceline is not None:
elem.set(linenumber_attribute, unicode_type(elem.sourceline))
elem.set(linenumber_attribute, str(elem.sourceline))
return ans
except Exception:
if log is not None:
+3 -3
View File
@@ -6,7 +6,7 @@ from ebook_converter.ebooks.oeb.base import barename, XPNSMAP, XPath, OPF, XHTML
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.builtins import iteritems
__license__ = 'GPL v3'
@@ -181,7 +181,7 @@ def split(container, name, loc_or_xpath, before=True, totals=None):
'''
root = container.parsed(name)
if isinstance(loc_or_xpath, unicode_type):
if isinstance(loc_or_xpath, str):
split_point = root.xpath(loc_or_xpath)[0]
else:
try:
@@ -279,7 +279,7 @@ def multisplit(container, name, xpath, before=True):
raise AbortError('Cannot split on the <body> tag')
for i, tag in enumerate(nodes):
tag.set('calibre-split-point', unicode_type(i))
tag.set('calibre-split-point', str(i))
current = name
all_names = [name]
+7 -7
View File
@@ -16,7 +16,7 @@ from ebook_converter.ebooks.oeb.polish.utils import guess_type, extract
from ebook_converter.ebooks.oeb.polish.opf import set_guide_item, get_book_language
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.builtins import iteritems
__license__ = 'GPL v3'
@@ -170,11 +170,11 @@ def parse_ncx(container, ncx_name):
toc_root.lang = toc_root.uid = None
for attr, val in iteritems(root.attrib):
if attr.endswith('lang'):
toc_root.lang = unicode_type(val)
toc_root.lang = str(val)
break
for uid in root.xpath('//*[calibre:lower-case(local-name()) = "meta" and @name="dtb:uid"]/@content'):
if uid:
toc_root.uid = unicode_type(uid)
toc_root.uid = str(uid)
break
for pl in root.xpath('//*[calibre:lower-case(local-name()) = "pagelist"]'):
for pt in pl.xpath('descendant::*[calibre:lower-case(local-name()) = "pagetarget"]'):
@@ -581,9 +581,9 @@ def create_ncx(toc, to_href, btitle, lang, uid):
nsmap={None: NCX_NS})
head = etree.SubElement(ncx, NCX('head'))
etree.SubElement(head, NCX('meta'),
name='dtb:uid', content=unicode_type(uid))
name='dtb:uid', content=str(uid))
etree.SubElement(head, NCX('meta'),
name='dtb:depth', content=unicode_type(toc.depth))
name='dtb:depth', content=str(toc.depth))
generator = ''.join(['calibre (', __version__, ')'])
etree.SubElement(head, NCX('meta'),
name='dtb:generator', content=generator)
@@ -601,7 +601,7 @@ def create_ncx(toc, to_href, btitle, lang, uid):
for child in toc_parent:
play_order['c'] += 1
point = etree.SubElement(xml_parent, NCX('navPoint'), id='num_%d' % play_order['c'],
playOrder=unicode_type(play_order['c']))
playOrder=str(play_order['c']))
label = etree.SubElement(point, NCX('navLabel'))
title = child.title
if title:
@@ -770,7 +770,7 @@ def commit_nav_toc(container, toc, lang=None, landmarks=None, previous_nav=None)
for entry in toc.page_list:
if container.has_name(entry['dest']) and container.mime_map[entry['dest']] in OEB_DOCS:
a = create_li(ol, entry)
a.text = unicode_type(entry['pagenum'])
a.text = str(entry['pagenum'])
pretty_xml_tree(nav)
collapse_li(nav)
container.replace(tocname, root)