py3: Port use of no longer extant elements package

This commit is contained in:
Kovid Goyal 2019-04-04 13:54:29 +05:30
parent 6987e86108
commit a7f3fd798b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -37,16 +37,11 @@ from __future__ import print_function
# Plot, Image (outside of ImageBlock),
# EmpLine, EmpDots
import os, re, codecs, operator
import os, re, codecs, operator, io
from xml.sax.saxutils import escape
from datetime import date
try:
from elementtree.ElementTree import (Element, SubElement)
Element, SubElement
except ImportError:
from xml.etree.ElementTree import (Element, SubElement)
from xml.etree.ElementTree import Element, SubElement, ElementTree
from elements import ElementWriter
from pylrf import (LrfWriter, LrfObject, LrfTag, LrfToc,
STREAM_COMPRESSED, LrfTagStream, LrfStreamBase, IMAGE_TYPE_ENCODING,
BINDING_DIRECTION_ENCODING, LINE_TYPE_ENCODING, LrfFileStream,
@ -624,12 +619,8 @@ class Book(Delegator):
# now, add some newlines to make it easier to look at
_formatXml(root)
writer = ElementWriter(root, header=True,
sourceEncoding=self.sourceencoding,
spaceBeforeClose=False,
outputEncodingName=outputEncodingName)
writer.write(f)
tree = ElementTree(element=root)
tree.write(f, encoding=outputEncodingName, xml_declaration=True)
class BookInformation(Delegator):
@ -679,9 +670,10 @@ class Info(Delegator):
# fix up the doc info to match the LRF format
# NB: generates an encoding attribute, which lrs2lrf does not
xmlInfo = ElementWriter(info, header=True, sourceEncoding=lrfWriter.getSourceEncoding(),
spaceBeforeClose=False).toString()
tree = ElementTree(element=info)
f = io.BytesIO()
tree.write(f, encoding='utf-8', xml_declaration=True)
xmlInfo = f.getvalue().decode('utf-8')
xmlInfo = re.sub(r"<CThumbnail.*?>\n", "", xmlInfo)
xmlInfo = xmlInfo.replace("SumPage>", "Page>")
lrfWriter.docInfoXml = xmlInfo