mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-27 01:01:28 +02:00
Removed polyglots unicode_type usage
This commit is contained in:
@@ -17,7 +17,7 @@ from ebook_converter import (isbytestring, as_unicode, get_types_map)
|
||||
from ebook_converter.ebooks.oeb.parse_utils import barename, XHTML_NS, namespace, XHTML, parse_html, NotHTML
|
||||
from ebook_converter.utils.cleantext import clean_xml_chars
|
||||
from ebook_converter.utils.short_uuid import uuid4
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes, itervalues, codepoint_to_chr
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes, itervalues, codepoint_to_chr
|
||||
from ebook_converter.polyglot.urllib import unquote as urlunquote
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ def as_string_type(pat, for_unicode):
|
||||
if isinstance(pat, bytes):
|
||||
pat = pat.decode('utf-8')
|
||||
else:
|
||||
if isinstance(pat, unicode_type):
|
||||
if isinstance(pat, str):
|
||||
pat = pat.encode('utf-8')
|
||||
return pat
|
||||
|
||||
@@ -140,7 +140,7 @@ def self_closing_pat(for_unicode):
|
||||
|
||||
|
||||
def close_self_closing_tags(raw):
|
||||
for_unicode = isinstance(raw, unicode_type)
|
||||
for_unicode = isinstance(raw, str)
|
||||
repl = as_string_type(r'<\g<tag>\g<arg>></\g<tag>>', for_unicode)
|
||||
pat = self_closing_pat(for_unicode)
|
||||
return pat.sub(repl, raw)
|
||||
@@ -421,11 +421,11 @@ def serialize(data, media_type, pretty_print=False):
|
||||
# incorrectly by some browser based renderers
|
||||
ans = close_self_closing_tags(ans)
|
||||
return ans
|
||||
if isinstance(data, unicode_type):
|
||||
if isinstance(data, str):
|
||||
return data.encode('utf-8')
|
||||
if hasattr(data, 'cssText'):
|
||||
data = data.cssText
|
||||
if isinstance(data, unicode_type):
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
return data + b'\n'
|
||||
return bytes(data)
|
||||
@@ -567,7 +567,7 @@ class DirContainer(object):
|
||||
# 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
|
||||
if isinstance(path, unicode_type):
|
||||
if isinstance(path, str):
|
||||
path = path.encode('utf-8')
|
||||
return urlunquote(path).decode('utf-8')
|
||||
|
||||
@@ -759,7 +759,7 @@ class Metadata(object):
|
||||
return as_unicode(self.value)
|
||||
else:
|
||||
def __str__(self):
|
||||
return unicode_type(self.value).encode('ascii', 'xmlcharrefreplace')
|
||||
return str(self.value).encode('ascii', 'xmlcharrefreplace')
|
||||
|
||||
def __unicode__(self):
|
||||
return as_unicode(self.value)
|
||||
@@ -918,9 +918,9 @@ class Manifest(object):
|
||||
"""
|
||||
|
||||
def __init__(self, oeb, id, href, media_type,
|
||||
fallback=None, loader=unicode_type, data=None):
|
||||
fallback=None, loader=str, data=None):
|
||||
if href:
|
||||
href = unicode_type(href)
|
||||
href = str(href)
|
||||
self.oeb = oeb
|
||||
self.id = id
|
||||
self.href = self.path = urlnormalize(href)
|
||||
@@ -973,7 +973,7 @@ class Manifest(object):
|
||||
|
||||
title = self.oeb.metadata.title
|
||||
if title:
|
||||
title = unicode_type(title[0])
|
||||
title = str(title[0])
|
||||
else:
|
||||
title = _('Unknown')
|
||||
|
||||
@@ -1006,7 +1006,7 @@ class Manifest(object):
|
||||
self.oeb.logger.warn('CSS import of non-CSS file %r' % path)
|
||||
return (None, None)
|
||||
data = item.data.cssText
|
||||
enc = None if isinstance(data, unicode_type) else 'utf-8'
|
||||
enc = None if isinstance(data, str) else 'utf-8'
|
||||
return (enc, data)
|
||||
|
||||
# }}}
|
||||
@@ -1087,11 +1087,11 @@ class Manifest(object):
|
||||
data = self.data
|
||||
if isinstance(data, etree._Element):
|
||||
return xml2text(data, pretty_print=self.oeb.pretty_print)
|
||||
if isinstance(data, unicode_type):
|
||||
if isinstance(data, str):
|
||||
return data
|
||||
if hasattr(data, 'cssText'):
|
||||
return css_text(data)
|
||||
return unicode_type(data)
|
||||
return str(data)
|
||||
|
||||
@property
|
||||
def bytes_representation(self):
|
||||
@@ -1211,7 +1211,7 @@ class Manifest(object):
|
||||
base = id
|
||||
index = 1
|
||||
while id in self.ids:
|
||||
id = base + unicode_type(index)
|
||||
id = base + str(index)
|
||||
index += 1
|
||||
if href is not None:
|
||||
href = urlnormalize(href)
|
||||
@@ -1219,9 +1219,9 @@ class Manifest(object):
|
||||
index = 1
|
||||
lhrefs = {x.lower() for x in self.hrefs}
|
||||
while href.lower() in lhrefs:
|
||||
href = base + unicode_type(index) + ext
|
||||
href = base + str(index) + ext
|
||||
index += 1
|
||||
return id, unicode_type(href)
|
||||
return id, str(href)
|
||||
|
||||
def __iter__(self):
|
||||
for item in self.items:
|
||||
@@ -1435,7 +1435,7 @@ class Guide(object):
|
||||
def add(self, type, title, href):
|
||||
"""Add a new reference to the `Guide`."""
|
||||
if href:
|
||||
href = unicode_type(href)
|
||||
href = str(href)
|
||||
ref = self.Reference(self.oeb, type, title, href)
|
||||
self.refs[type] = ref
|
||||
return ref
|
||||
@@ -1641,7 +1641,7 @@ class TOC(object):
|
||||
po = node.play_order
|
||||
if po == 0:
|
||||
po = 1
|
||||
attrib = {'id': id, 'playOrder': unicode_type(po)}
|
||||
attrib = {'id': id, 'playOrder': str(po)}
|
||||
if node.klass:
|
||||
attrib['class'] = node.klass
|
||||
point = element(parent, NCX('navPoint'), attrib=attrib)
|
||||
@@ -1712,7 +1712,7 @@ class PageList(object):
|
||||
TYPES = {'front', 'normal', 'special'}
|
||||
|
||||
def __init__(self, name, href, type='normal', klass=None, id=None):
|
||||
self.name = unicode_type(name)
|
||||
self.name = str(name)
|
||||
self.href = urlnormalize(href)
|
||||
self.type = type if type in self.TYPES else 'normal'
|
||||
self.id = id
|
||||
@@ -1749,7 +1749,7 @@ class PageList(object):
|
||||
for page in self.pages:
|
||||
id = page.id or uuid_id()
|
||||
type = page.type
|
||||
value = unicode_type(next(values[type]))
|
||||
value = str(next(values[type]))
|
||||
attrib = {'id': id, 'value': value, 'type': type, 'playOrder': '0'}
|
||||
if page.klass:
|
||||
attrib['class'] = page.klass
|
||||
@@ -1848,7 +1848,7 @@ class OEBBook(object):
|
||||
"""Automatically decode :param:`data` into a `unicode` 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'):
|
||||
@@ -1922,36 +1922,36 @@ class OEBBook(object):
|
||||
for i, elem in enumerate(xpath(ncx, '//*[@playOrder and ./ncx:content[@src]]')):
|
||||
href = urlnormalize(selector(elem)[0])
|
||||
order = playorder.get(href, i)
|
||||
elem.attrib['playOrder'] = unicode_type(order)
|
||||
elem.attrib['playOrder'] = str(order)
|
||||
return
|
||||
|
||||
def _to_ncx(self):
|
||||
lang = unicode_type(self.metadata.language[0])
|
||||
lang = str(self.metadata.language[0])
|
||||
lang = lang.replace('_', '-')
|
||||
ncx = etree.Element(NCX('ncx'),
|
||||
attrib={'version': '2005-1', XML('lang'): lang},
|
||||
nsmap={None: NCX_NS})
|
||||
head = etree.SubElement(ncx, NCX('head'))
|
||||
etree.SubElement(head, NCX('meta'),
|
||||
name='dtb:uid', content=unicode_type(self.uid))
|
||||
name='dtb:uid', content=str(self.uid))
|
||||
etree.SubElement(head, NCX('meta'),
|
||||
name='dtb:depth', content=unicode_type(self.toc.depth()))
|
||||
name='dtb:depth', content=str(self.toc.depth()))
|
||||
generator = ''.join(['calibre (', __version__, ')'])
|
||||
etree.SubElement(head, NCX('meta'),
|
||||
name='dtb:generator', content=generator)
|
||||
etree.SubElement(head, NCX('meta'),
|
||||
name='dtb:totalPageCount', content=unicode_type(len(self.pages)))
|
||||
name='dtb:totalPageCount', content=str(len(self.pages)))
|
||||
maxpnum = etree.SubElement(head, NCX('meta'),
|
||||
name='dtb:maxPageNumber', content='0')
|
||||
title = etree.SubElement(ncx, NCX('docTitle'))
|
||||
text = etree.SubElement(title, NCX('text'))
|
||||
text.text = unicode_type(self.metadata.title[0])
|
||||
text.text = str(self.metadata.title[0])
|
||||
navmap = etree.SubElement(ncx, NCX('navMap'))
|
||||
self.toc.to_ncx(navmap)
|
||||
if len(self.pages) > 0:
|
||||
plist = self.pages.to_ncx(ncx)
|
||||
value = max(int(x) for x in xpath(plist, '//@value'))
|
||||
maxpnum.attrib['content'] = unicode_type(value)
|
||||
maxpnum.attrib['content'] = str(value)
|
||||
self._update_playorder(ncx)
|
||||
return ncx
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from css_parser.css import PropertyValue
|
||||
from css_parser import profile as cssprofiles, CSSParser
|
||||
from ebook_converter.tinycss.fonts3 import parse_font, serialize_font_family
|
||||
from ebook_converter.ebooks.oeb.base import css_text
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -390,7 +390,7 @@ def test_normalization(return_tests=False): # {{{
|
||||
tuple('0 0 0 0'.split()) : '0',
|
||||
}):
|
||||
for prefix in ('margin', 'padding'):
|
||||
css = {'%s-%s' % (prefix, x) : unicode_type(y)+'pt' if isinstance(y, numbers.Number) else y
|
||||
css = {'%s-%s' % (prefix, x) : str(y)+'pt' if isinstance(y, numbers.Number) else y
|
||||
for x, y in zip(('left', 'top', 'right', 'bottom'), s)}
|
||||
css = '; '.join(('%s:%s' % (k, v) for k, v in iteritems(css)))
|
||||
style = parseStyle(css)
|
||||
|
||||
@@ -6,7 +6,7 @@ from ebook_converter import xml_replace_entities, force_unicode
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.constants import filesystem_encoding
|
||||
from ebook_converter.ebooks.chardet import xml_to_unicode, strip_encoding_declarations
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type, string_or_bytes
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -162,7 +162,7 @@ def parse_html(data, log=None, decoder=None, preprocessor=None,
|
||||
|
||||
filename = force_unicode(filename, enc=filesystem_encoding)
|
||||
|
||||
if not isinstance(data, unicode_type):
|
||||
if not isinstance(data, str):
|
||||
if decoder is not None:
|
||||
data = decoder(data)
|
||||
else:
|
||||
@@ -244,7 +244,7 @@ def parse_html(data, log=None, decoder=None, preprocessor=None,
|
||||
nroot = safe_xml_fromstring('<html></html>')
|
||||
has_body = False
|
||||
for child in list(data):
|
||||
if isinstance(child.tag, (unicode_type, bytes)) and barename(child.tag) == 'body':
|
||||
if isinstance(child.tag, (str, bytes)) and barename(child.tag) == 'body':
|
||||
has_body = True
|
||||
break
|
||||
parent = nroot
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -23,7 +23,6 @@ from ebook_converter.utils.localization import get_lang
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.constants import __appname__, __version__
|
||||
from ebook_converter import guess_type, xml_replace_entities
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
|
||||
|
||||
@@ -144,7 +143,7 @@ class OEBReader(object):
|
||||
dict(a=__appname__, v=__version__)
|
||||
meta_info_to_oeb_metadata(mi, self.oeb.metadata, self.logger)
|
||||
m = self.oeb.metadata
|
||||
m.add('identifier', unicode_type(uuid.uuid4()), id='uuid_id', scheme='uuid')
|
||||
m.add('identifier', str(uuid.uuid4()), id='uuid_id', scheme='uuid')
|
||||
self.oeb.uid = self.oeb.metadata.identifier[-1]
|
||||
if not m.title:
|
||||
m.add('title', self.oeb.translate(__('Unknown')))
|
||||
@@ -447,7 +446,7 @@ class OEBReader(object):
|
||||
ncx = item.data
|
||||
title = ''.join(xpath(ncx, 'ncx:docTitle/ncx:text/text()'))
|
||||
title = COLLAPSE_RE.sub(' ', title.strip())
|
||||
title = title or unicode_type(self.oeb.metadata.title[0])
|
||||
title = title or str(self.oeb.metadata.title[0])
|
||||
toc = self.oeb.toc
|
||||
toc.title = title
|
||||
navmaps = xpath(ncx, 'ncx:navMap')
|
||||
@@ -634,7 +633,7 @@ class OEBReader(object):
|
||||
|
||||
def _locate_cover_image(self):
|
||||
if self.oeb.metadata.cover:
|
||||
id = unicode_type(self.oeb.metadata.cover[0])
|
||||
id = str(self.oeb.metadata.cover[0])
|
||||
item = self.oeb.manifest.ids.get(id, None)
|
||||
if item is not None and item.media_type in OEB_IMAGES:
|
||||
return item
|
||||
|
||||
@@ -15,7 +15,7 @@ from ebook_converter.ebooks import unit_convert
|
||||
from ebook_converter.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES, xpath, urlnormalize
|
||||
from ebook_converter.ebooks.oeb.normalize_css import DEFAULTS, normalizers
|
||||
from ebook_converter.css_selectors import Select, SelectorError, INAPPROPRIATE_PSEUDO_CLASSES
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
from ebook_converter.tinycss.media3 import CSSMedia3Parser
|
||||
|
||||
|
||||
@@ -317,7 +317,7 @@ class Stylizer(object):
|
||||
for x in elem.iter('*'):
|
||||
if x.text:
|
||||
punctuation_chars = []
|
||||
text = unicode_type(x.text)
|
||||
text = str(x.text)
|
||||
while text:
|
||||
category = unicodedata.category(text[0])
|
||||
if category[0] not in {'P', 'Z'}:
|
||||
@@ -591,7 +591,7 @@ class Style(object):
|
||||
x = self._style.get(attr)
|
||||
if x is not None:
|
||||
if x == 'auto':
|
||||
ans = self._unit_convert(unicode_type(img_size) + 'px', base=base)
|
||||
ans = self._unit_convert(str(img_size) + 'px', base=base)
|
||||
else:
|
||||
x = self._unit_convert(x, base=base)
|
||||
if isinstance(x, numbers.Number):
|
||||
@@ -603,7 +603,7 @@ class Style(object):
|
||||
if isinstance(x, numbers.Number):
|
||||
ans = x
|
||||
if ans is None:
|
||||
ans = self._unit_convert(unicode_type(img_size) + 'px', base=base)
|
||||
ans = self._unit_convert(str(img_size) + 'px', base=base)
|
||||
maa = self._style.get('max-' + attr)
|
||||
if maa is not None:
|
||||
x = self._unit_convert(maa, base=base)
|
||||
@@ -639,12 +639,12 @@ class Style(object):
|
||||
result = base
|
||||
else:
|
||||
result = self._unit_convert(width, base=base)
|
||||
if isinstance(result, (unicode_type, bytes)):
|
||||
if isinstance(result, (str, bytes)):
|
||||
result = self._profile.width
|
||||
self._width = result
|
||||
if 'max-width' in self._style:
|
||||
result = self._unit_convert(self._style['max-width'], base=base)
|
||||
if isinstance(result, (unicode_type, bytes)):
|
||||
if isinstance(result, (str, bytes)):
|
||||
result = self._width
|
||||
if result < self._width:
|
||||
self._width = result
|
||||
@@ -676,12 +676,12 @@ class Style(object):
|
||||
result = base
|
||||
else:
|
||||
result = self._unit_convert(height, base=base)
|
||||
if isinstance(result, (unicode_type, bytes)):
|
||||
if isinstance(result, (str, bytes)):
|
||||
result = self._profile.height
|
||||
self._height = result
|
||||
if 'max-height' in self._style:
|
||||
result = self._unit_convert(self._style['max-height'], base=base)
|
||||
if isinstance(result, (unicode_type, bytes)):
|
||||
if isinstance(result, (str, bytes)):
|
||||
result = self._height
|
||||
if result < self._height:
|
||||
self._height = result
|
||||
|
||||
@@ -4,7 +4,6 @@ import urllib.parse
|
||||
from ebook_converter import guess_type
|
||||
from ebook_converter.utils.imghdr import identify
|
||||
from ebook_converter.utils.xml_parse import safe_xml_fromstring
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
|
||||
|
||||
@@ -111,9 +110,9 @@ class CoverManager(object):
|
||||
self.svg_template = self.svg_template.replace('__viewbox__',
|
||||
'0 0 %d %d'%(width, height))
|
||||
self.svg_template = self.svg_template.replace('__width__',
|
||||
unicode_type(width))
|
||||
str(width))
|
||||
self.svg_template = self.svg_template.replace('__height__',
|
||||
unicode_type(height))
|
||||
str(height))
|
||||
|
||||
if href is not None:
|
||||
templ = self.non_svg_template if self.no_svg_cover \
|
||||
|
||||
@@ -16,7 +16,7 @@ from ebook_converter.ebooks.oeb.base import (XHTML, XHTML_NS, CSS_MIME, OEB_STYL
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
from ebook_converter.utils.filenames import ascii_filename, ascii_text
|
||||
from ebook_converter.utils.icu import numeric_sort_key
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type, string_or_bytes
|
||||
from ebook_converter.polyglot.builtins import iteritems, string_or_bytes
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -250,7 +250,7 @@ class CSSFlattener(object):
|
||||
|
||||
cfont = {
|
||||
'font-family': '"%s"'%font['font-family'],
|
||||
'panose-1': ' '.join(map(unicode_type, font['panose'])),
|
||||
'panose-1': ' '.join(map(str, font['panose'])),
|
||||
'src': 'url(%s)'%item.href,
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ class CSSFlattener(object):
|
||||
minlh = self.context.minimum_line_height / 100.
|
||||
slh = style['line-height']
|
||||
if not is_drop_cap and isinstance(slh, numbers.Number) and slh < minlh * fsize:
|
||||
cssdict['line-height'] = unicode_type(minlh)
|
||||
cssdict['line-height'] = str(minlh)
|
||||
except Exception:
|
||||
self.oeb.logger.exception('Failed to set minimum line-height')
|
||||
|
||||
@@ -538,7 +538,7 @@ class CSSFlattener(object):
|
||||
if css in styles:
|
||||
match = styles[css]
|
||||
else:
|
||||
match = klass + unicode_type(names[klass] or '')
|
||||
match = klass + str(names[klass] or '')
|
||||
styles[css] = match
|
||||
names[klass] += 1
|
||||
node.attrib['class'] = match
|
||||
@@ -558,7 +558,7 @@ class CSSFlattener(object):
|
||||
# then the class attribute for a.x tags will contain both
|
||||
# that class and the class for a.x:hover, which is wrong.
|
||||
klass = 'pcalibre'
|
||||
match = klass + unicode_type(names[klass] or '')
|
||||
match = klass + str(names[klass] or '')
|
||||
pstyles[css] = match
|
||||
names[klass] += 1
|
||||
keep_classes.add(match)
|
||||
|
||||
@@ -4,7 +4,6 @@ HTML-TOC-adding transform.
|
||||
from ebook_converter.ebooks.oeb.base import XML, XHTML, XHTML_NS
|
||||
from ebook_converter.ebooks.oeb.base import XHTML_MIME, CSS_MIME
|
||||
from ebook_converter.ebooks.oeb.base import element, XPath
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__all__ = ['HTMLTOCAdder']
|
||||
@@ -93,7 +92,7 @@ class HTMLTOCAdder(object):
|
||||
style = 'nested'
|
||||
id, css_href = oeb.manifest.generate('tocstyle', 'tocstyle.css')
|
||||
oeb.manifest.add(id, css_href, CSS_MIME, data=STYLE_CSS[style])
|
||||
language = unicode_type(oeb.metadata.language[0])
|
||||
language = str(oeb.metadata.language[0])
|
||||
contents = element(None, XHTML('html'), nsmap={None: XHTML_NS},
|
||||
attrib={XML('lang'): language})
|
||||
head = element(contents, XHTML('head'))
|
||||
|
||||
@@ -11,7 +11,6 @@ from ebook_converter.library.comments import comments_to_html, markdown
|
||||
from ebook_converter.utils.date import is_date_undefined, as_local_time
|
||||
from ebook_converter.ebooks.chardet import strip_encoding_declarations
|
||||
from ebook_converter.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -99,22 +98,22 @@ class Jacket(Base):
|
||||
self.log('Inserting metadata into book...')
|
||||
|
||||
try:
|
||||
tags = list(map(unicode_type, self.oeb.metadata.subject))
|
||||
tags = list(map(str, self.oeb.metadata.subject))
|
||||
except Exception:
|
||||
tags = []
|
||||
|
||||
try:
|
||||
comments = unicode_type(self.oeb.metadata.description[0])
|
||||
comments = str(self.oeb.metadata.description[0])
|
||||
except:
|
||||
comments = ''
|
||||
|
||||
try:
|
||||
title = unicode_type(self.oeb.metadata.title[0])
|
||||
title = str(self.oeb.metadata.title[0])
|
||||
except:
|
||||
title = _('Unknown')
|
||||
|
||||
try:
|
||||
authors = list(map(unicode_type, self.oeb.metadata.creator))
|
||||
authors = list(map(str, self.oeb.metadata.creator))
|
||||
except:
|
||||
authors = [_('Unknown')]
|
||||
|
||||
@@ -171,7 +170,7 @@ def get_rating(rating, rchar, e_rchar):
|
||||
return ans
|
||||
|
||||
|
||||
class Series(unicode_type):
|
||||
class Series(str):
|
||||
|
||||
def __new__(self, series, series_index):
|
||||
if series and series_index is not None:
|
||||
@@ -181,7 +180,7 @@ class Series(unicode_type):
|
||||
escape(series), escape(fmt_sidx(series_index, use_roman=False)))
|
||||
else:
|
||||
combined = roman = escape(series or u'')
|
||||
s = unicode_type.__new__(self, combined)
|
||||
s = str.__new__(self, combined)
|
||||
s.roman = roman
|
||||
s.name = escape(series or '')
|
||||
s.number = escape(fmt_sidx(series_index or 1.0, use_roman=False))
|
||||
@@ -189,11 +188,11 @@ class Series(unicode_type):
|
||||
return s
|
||||
|
||||
|
||||
class Tags(unicode_type):
|
||||
class Tags(str):
|
||||
|
||||
def __new__(self, tags, output_profile):
|
||||
tags = [escape(x) for x in tags or ()]
|
||||
t = unicode_type.__new__(self, ', '.join(tags))
|
||||
t = str.__new__(self, ', '.join(tags))
|
||||
t.alphabetical = ', '.join(sorted(tags))
|
||||
t.tags_list = tags
|
||||
return t
|
||||
|
||||
@@ -15,7 +15,6 @@ from ebook_converter.ebooks.oeb.base import urlnormalize
|
||||
from ebook_converter.ebooks.oeb.stylizer import Stylizer
|
||||
from ebook_converter.ptempfile import PersistentTemporaryFile
|
||||
from ebook_converter.utils.imghdr import what
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -78,7 +77,7 @@ class SVGRasterizer(object):
|
||||
logger.info('Found SVG image height in %, trying to convert...')
|
||||
try:
|
||||
h = float(image.get('height').replace('%', ''))/100.
|
||||
image.set('height', unicode_type(h*sizes[1]))
|
||||
image.set('height', str(h*sizes[1]))
|
||||
except:
|
||||
logger.exception('Failed to convert percentage height:',
|
||||
image.get('height'))
|
||||
@@ -224,11 +223,11 @@ class SVGRasterizer(object):
|
||||
covers = self.oeb.metadata.cover
|
||||
if not covers:
|
||||
return
|
||||
if unicode_type(covers[0]) not in self.oeb.manifest.ids:
|
||||
if str(covers[0]) not in self.oeb.manifest.ids:
|
||||
self.oeb.logger.warn('Cover not in manifest, skipping.')
|
||||
self.oeb.metadata.clear('cover')
|
||||
return
|
||||
cover = self.oeb.manifest.ids[unicode_type(covers[0])]
|
||||
cover = self.oeb.manifest.ids[str(covers[0])]
|
||||
if not cover.media_type == SVG_MIME:
|
||||
return
|
||||
width = (self.profile.width / 72) * self.profile.dpi
|
||||
|
||||
@@ -15,7 +15,7 @@ from ebook_converter.ebooks.epub import rules
|
||||
from ebook_converter.ebooks.oeb.base import (OEB_STYLES, XPNSMAP as NAMESPACES,
|
||||
rewrite_links, XHTML, urlnormalize)
|
||||
from ebook_converter.ebooks.oeb.polish.split import do_split
|
||||
from ebook_converter.polyglot.builtins import iteritems, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
from ebook_converter.css_selectors import Select, SelectorError
|
||||
|
||||
@@ -122,7 +122,7 @@ class Split(object):
|
||||
|
||||
for i, elem in enumerate(item.data.iter('*')):
|
||||
try:
|
||||
elem.set('pb_order', unicode_type(i))
|
||||
elem.set('pb_order', str(i))
|
||||
except TypeError: # Cant set attributes on comment nodes etc.
|
||||
continue
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from collections import OrderedDict, Counter
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text, barename
|
||||
from ebook_converter.ebooks import ConversionError
|
||||
from ebook_converter.polyglot.builtins import itervalues, unicode_type
|
||||
from ebook_converter.polyglot.builtins import itervalues
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
@@ -122,7 +122,7 @@ class DetectStructure(object):
|
||||
elem = matches[0]
|
||||
eid = elem.get('id', None)
|
||||
if not eid:
|
||||
eid = 'start_reading_at_'+unicode_type(uuid.uuid4()).replace('-', '')
|
||||
eid = 'start_reading_at_'+str(uuid.uuid4()).replace('-', '')
|
||||
elem.set('id', eid)
|
||||
if 'text' in self.oeb.guide:
|
||||
self.oeb.guide.remove('text')
|
||||
|
||||
@@ -2,7 +2,7 @@ from collections import defaultdict
|
||||
|
||||
from ebook_converter.ebooks.oeb.base import urlnormalize, css_text
|
||||
from ebook_converter.utils.fonts.sfnt.subset import subset, NoGlyphs, UnsupportedFont
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues, unicode_type
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
from ebook_converter.tinycss.fonts3 import parse_font_family
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ def get_font_properties(rule, default=None):
|
||||
except (IndexError, KeyError, AttributeError, TypeError, ValueError):
|
||||
val = None if q in {'src', 'font-family'} else default
|
||||
if q in {'font-weight', 'font-stretch', 'font-style'}:
|
||||
val = unicode_type(val).lower() if (val or val == 0) else val
|
||||
val = str(val).lower() if (val or val == 0) else val
|
||||
if val == 'inherit':
|
||||
val = default
|
||||
if q == 'font-weight':
|
||||
@@ -233,7 +233,7 @@ class SubsetFonts(object):
|
||||
no match is found (can happen if no family matches).
|
||||
'''
|
||||
ff = style.get('font-family', [])
|
||||
lnames = {unicode_type(x).lower() for x in ff}
|
||||
lnames = {str(x).lower() for x in ff}
|
||||
matching_set = []
|
||||
|
||||
# Filter on font-family
|
||||
|
||||
Reference in New Issue
Block a user