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