1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-27 17:13:32 +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
+39 -39
View File
@@ -51,7 +51,7 @@ DEFAULT_GENREADING = "fs" # default is yes to both lrf and lrs
from ebook_converter import __appname__, __version__
from ebook_converter import entity_to_unicode
from ebook_converter.polyglot.builtins import string_or_bytes, unicode_type, iteritems, native_string_type
from ebook_converter.polyglot.builtins import string_or_bytes, iteritems, native_string_type
class LrsError(Exception):
@@ -226,7 +226,7 @@ class LrsAttributes(object):
raise LrsError("%s does not support setting %s" %
(self.__class__.__name__, name))
if isinstance(value, int):
value = unicode_type(value)
value = str(value)
self.attrs[name] = value
@@ -330,13 +330,13 @@ class LrsObject(object):
def lrsObjectElement(self, name, objlabel="objlabel", labelName=None,
labelDecorate=True, **settings):
element = Element(name)
element.attrib["objid"] = unicode_type(self.objId)
element.attrib["objid"] = str(self.objId)
if labelName is None:
labelName = name
if labelDecorate:
label = "%s.%d" % (labelName, self.objId)
else:
label = unicode_type(self.objId)
label = str(self.objId)
element.attrib[objlabel] = label
element.attrib.update(settings)
return element
@@ -562,7 +562,7 @@ class Book(Delegator):
factor = base_font_size / old_base_font_size
def rescale(old):
return unicode_type(int(int(old) * factor))
return str(int(int(old) * factor))
text_blocks = list(main.get_all(lambda x: isinstance(x, TextBlock)))
for tb in text_blocks:
@@ -693,7 +693,7 @@ class TableOfContents(object):
def addTocEntry(self, tocLabel, textBlock):
if not isinstance(textBlock, (Canvas, TextBlock, ImageBlock, RuledLine)):
raise LrsError("TOC destination must be a Canvas, TextBlock, ImageBlock or RuledLine"+
" not a " + unicode_type(type(textBlock)))
" not a " + str(type(textBlock)))
if textBlock.parent is None:
raise LrsError("TOC text block must be already appended to a page")
@@ -743,8 +743,8 @@ class TocLabel(object):
def toElement(self, se):
return ElementWithText("TocLabel", self.label,
refobj=unicode_type(self.textBlock.objId),
refpage=unicode_type(self.textBlock.parent.objId))
refobj=str(self.textBlock.objId),
refpage=str(self.textBlock.parent.objId))
class BookInfo(object):
@@ -805,7 +805,7 @@ class DocInfo(object):
self.thumbnail = None
self.language = "en"
self.creator = None
self.creationdate = unicode_type(isoformat(date.today()))
self.creationdate = str(isoformat(date.today()))
self.producer = "%s v%s"%(__appname__, __version__)
self.numberofpages = "0"
@@ -829,7 +829,7 @@ class DocInfo(object):
docInfo.append(ElementWithText("Creator", self.creator))
docInfo.append(ElementWithText("CreationDate", self.creationdate))
docInfo.append(ElementWithText("Producer", self.producer))
docInfo.append(ElementWithText("SumPage", unicode_type(self.numberofpages)))
docInfo.append(ElementWithText("SumPage", str(self.numberofpages)))
return docInfo
@@ -1091,7 +1091,7 @@ class LrsStyle(LrsObject, LrsAttributes, LrsContainer):
self.elementName = elementName
self.objectsAppended = False
# self.label = "%s.%d" % (elementName, self.objId)
# self.label = unicode_type(self.objId)
# self.label = str(self.objId)
# self.parent = None
def update(self, settings):
@@ -1101,11 +1101,11 @@ class LrsStyle(LrsObject, LrsAttributes, LrsContainer):
self.attrs[name] = value
def getLabel(self):
return unicode_type(self.objId)
return str(self.objId)
def toElement(self, se):
element = Element(self.elementName, stylelabel=self.getLabel(),
objid=unicode_type(self.objId))
objid=str(self.objId))
element.attrib.update(self.attrs)
return element
@@ -1236,14 +1236,14 @@ class PageStyle(LrsStyle):
del settings[evenbase]
if evenObj.parent is None:
parent.append(evenObj)
settings[evenbase + "id"] = unicode_type(evenObj.objId)
settings[evenbase + "id"] = str(evenObj.objId)
if oddbase in settings:
oddObj = settings[oddbase]
del settings[oddbase]
if oddObj.parent is None:
parent.append(oddObj)
settings[oddbase + "id"] = unicode_type(oddObj.objId)
settings[oddbase + "id"] = str(oddObj.objId)
def appendReferencedObjects(self, parent):
if self.objectsAppended:
@@ -1486,7 +1486,7 @@ class Paragraph(LrsContainer):
def __init__(self, text=None):
LrsContainer.__init__(self, [Text, CR, DropCaps, CharButton,
LrsSimpleChar1, bytes, unicode_type])
LrsSimpleChar1, bytes, str])
if text is not None:
if isinstance(text, string_or_bytes):
text = Text(text)
@@ -1521,7 +1521,7 @@ class Paragraph(LrsContainer):
class LrsTextTag(LrsContainer):
def __init__(self, text, validContents):
LrsContainer.__init__(self, [Text, bytes, unicode_type] + validContents)
LrsContainer.__init__(self, [Text, bytes, str] + validContents)
if text is not None:
self.append(text)
@@ -1580,7 +1580,7 @@ class DropCaps(LrsTextTag):
return self.text is None or not self.text.strip()
def toElement(self, se):
elem = Element('DrawChar', line=unicode_type(self.line))
elem = Element('DrawChar', line=str(self.line))
appendTextElements(elem, self.contents, se)
return elem
@@ -1656,7 +1656,7 @@ class JumpTo(LrsContainer):
self.textBlock = textBlock
def toElement(self, se):
return Element("JumpTo", refpage=unicode_type(self.textBlock.parent.objId), refobj=unicode_type(self.textBlock.objId))
return Element("JumpTo", refpage=str(self.textBlock.parent.objId), refobj=str(self.textBlock.objId))
class Plot(LrsSimpleChar1, LrsContainer):
@@ -1688,8 +1688,8 @@ class Plot(LrsSimpleChar1, LrsContainer):
parent.append(self.obj)
def toElement(self, se):
elem = Element('Plot', xsize=unicode_type(self.xsize), ysize=unicode_type(self.ysize),
refobj=unicode_type(self.obj.objId))
elem = Element('Plot', xsize=str(self.xsize), ysize=str(self.ysize),
refobj=str(self.obj.objId))
if self.adjustment:
elem.set('adjustment', self.adjustment)
return elem
@@ -1771,7 +1771,7 @@ class Space(LrsSimpleChar1, LrsContainer):
if self.xsize == 0:
return
return Element("Space", xsize=unicode_type(self.xsize))
return Element("Space", xsize=str(self.xsize))
def toLrfContainer(self, lrfWriter, container):
if self.xsize != 0:
@@ -1785,7 +1785,7 @@ class Box(LrsSimpleChar1, LrsContainer):
"""
def __init__(self, linetype="solid"):
LrsContainer.__init__(self, [Text, bytes, unicode_type])
LrsContainer.__init__(self, [Text, bytes, str])
if linetype not in LINE_TYPE_ENCODING:
raise LrsError(linetype + " is not a valid line type")
self.linetype = linetype
@@ -1805,7 +1805,7 @@ class Box(LrsSimpleChar1, LrsContainer):
class Span(LrsSimpleChar1, LrsContainer):
def __init__(self, text=None, **attrs):
LrsContainer.__init__(self, [LrsSimpleChar1, Text, bytes, unicode_type])
LrsContainer.__init__(self, [LrsSimpleChar1, Text, bytes, str])
if text is not None:
if isinstance(text, string_or_bytes):
text = Text(text)
@@ -1858,7 +1858,7 @@ class Span(LrsSimpleChar1, LrsContainer):
def toElement(self, se):
element = Element('Span')
for (key, value) in self.attrs.items():
element.set(key, unicode_type(value))
element.set(key, str(value))
appendTextElements(element, self.contents, se)
return element
@@ -1871,9 +1871,9 @@ class EmpLine(LrsTextTag, LrsSimpleChar1):
def __init__(self, text=None, emplineposition='before', emplinetype='solid'):
LrsTextTag.__init__(self, text, [LrsSimpleChar1])
if emplineposition not in self.__class__.emplinepositions:
raise LrsError('emplineposition for an EmpLine must be one of: '+unicode_type(self.__class__.emplinepositions))
raise LrsError('emplineposition for an EmpLine must be one of: '+str(self.__class__.emplinepositions))
if emplinetype not in self.__class__.emplinetypes:
raise LrsError('emplinetype for an EmpLine must be one of: '+unicode_type(self.__class__.emplinetypes))
raise LrsError('emplinetype for an EmpLine must be one of: '+str(self.__class__.emplinetypes))
self.emplinetype = emplinetype
self.emplineposition = emplineposition
@@ -1933,9 +1933,9 @@ class BlockSpace(LrsContainer):
element = Element("BlockSpace")
if self.xspace != 0:
element.attrib["xspace"] = unicode_type(self.xspace)
element.attrib["xspace"] = str(self.xspace)
if self.yspace != 0:
element.attrib["yspace"] = unicode_type(self.yspace)
element.attrib["yspace"] = str(self.yspace)
return element
@@ -1949,7 +1949,7 @@ class CharButton(LrsSimpleChar1, LrsContainer):
"""
def __init__(self, button, text=None):
LrsContainer.__init__(self, [bytes, unicode_type, Text, LrsSimpleChar1])
LrsContainer.__init__(self, [bytes, str, Text, LrsSimpleChar1])
self.button = None
if button is not None:
self.setButton(button)
@@ -1979,7 +1979,7 @@ class CharButton(LrsSimpleChar1, LrsContainer):
container.appendLrfTag(LrfTag("CharButtonEnd"))
def toElement(self, se):
cb = Element("CharButton", refobj=unicode_type(self.button.objId))
cb = Element("CharButton", refobj=str(self.button.objId))
appendTextElements(cb, self.contents, se)
return cb
@@ -2081,8 +2081,8 @@ class JumpButton(LrsObject, LrsContainer):
b = self.lrsObjectElement("Button")
pb = SubElement(b, "PushButton")
SubElement(pb, "JumpTo",
refpage=unicode_type(self.textBlock.parent.objId),
refobj=unicode_type(self.textBlock.objId))
refpage=str(self.textBlock.parent.objId),
refobj=str(self.textBlock.objId))
return b
@@ -2230,8 +2230,8 @@ class PutObj(LrsContainer):
self.content.objId)))
def toElement(self, se):
el = Element("PutObj", x1=unicode_type(self.x1), y1=unicode_type(self.y1),
refobj=unicode_type(self.content.objId))
el = Element("PutObj", x1=str(self.x1), y1=str(self.y1),
refobj=str(self.content.objId))
return el
@@ -2313,9 +2313,9 @@ class Image(LrsObject, LrsContainer, LrsAttributes):
def toElement(self, se):
element = self.lrsObjectElement("Image", **self.attrs)
element.set("refstream", unicode_type(self.refstream.objId))
element.set("refstream", str(self.refstream.objId))
for name in ["x0", "y0", "x1", "y1", "xsize", "ysize"]:
element.set(name, unicode_type(getattr(self, name)))
element.set(name, str(getattr(self, name)))
return element
def toLrf(self, lrfWriter):
@@ -2396,9 +2396,9 @@ class ImageBlock(LrsObject, LrsContainer, LrsAttributes):
def toElement(self, se):
element = self.lrsObjectElement("ImageBlock", **self.attrs)
element.set("refstream", unicode_type(self.refstream.objId))
element.set("refstream", str(self.refstream.objId))
for name in ["x0", "y0", "x1", "y1", "xsize", "ysize"]:
element.set(name, unicode_type(getattr(self, name)))
element.set(name, str(getattr(self, name)))
element.text = self.alttext
return element