mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-25 07:51:28 +02:00
Removed polyglots unicode_type usage
This commit is contained in:
@@ -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