mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
py3: Get rid of the last cStringIO
This commit is contained in:
parent
d59d91374a
commit
9b3e525610
@ -25,7 +25,7 @@ import zipfile
|
||||
from xml.sax import make_parser,handler
|
||||
from xml.sax.xmlreader import InputSource
|
||||
import xml.sax.saxutils
|
||||
from cStringIO import StringIO
|
||||
import io
|
||||
|
||||
MANIFESTNS="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
|
||||
|
||||
@ -97,7 +97,7 @@ def manifestlist(manifestxml):
|
||||
parser.setErrorHandler(handler.ErrorHandler())
|
||||
|
||||
inpsrc = InputSource()
|
||||
inpsrc.setByteStream(StringIO(manifestxml))
|
||||
inpsrc.setByteStream(io.BytesIO(manifestxml))
|
||||
parser.setFeature(handler.feature_external_ges, False) # Changed by Kovid to ignore external DTDs
|
||||
parser.parse(inpsrc)
|
||||
|
||||
@ -114,4 +114,3 @@ if __name__ == "__main__":
|
||||
result = odfmanifest(sys.argv[1])
|
||||
for file in result.values():
|
||||
print("%-40s %-40s" % (file['media-type'], file['full-path']))
|
||||
|
||||
|
@ -29,6 +29,7 @@ import element
|
||||
from attrconverters import make_NCName
|
||||
from xml.sax.xmlreader import InputSource
|
||||
from odfmanifest import manifestlist
|
||||
from polyglot.io import PolyglotBytesIO
|
||||
|
||||
__version__= TOOLSVERSION
|
||||
|
||||
@ -151,13 +152,13 @@ class OpenDocument:
|
||||
self._styles_dict[name] = element
|
||||
|
||||
def toXml(self, filename=''):
|
||||
xml=StringIO()
|
||||
xml=PolyglotBytesIO()
|
||||
xml.write(_XMLPROLOGUE)
|
||||
self.body.toXml(0, xml)
|
||||
if not filename:
|
||||
return xml.getvalue()
|
||||
else:
|
||||
f=file(filename,'w')
|
||||
f=file(filename,'wb')
|
||||
f.write(xml.getvalue())
|
||||
f.close()
|
||||
|
||||
@ -166,7 +167,7 @@ class OpenDocument:
|
||||
Always written as a bytestream in UTF-8 encoding
|
||||
"""
|
||||
self.__replaceGenerator()
|
||||
xml=StringIO()
|
||||
xml=PolyglotBytesIO()
|
||||
xml.write(_XMLPROLOGUE)
|
||||
self.topnode.toXml(0, xml)
|
||||
return xml.getvalue()
|
||||
|
Loading…
x
Reference in New Issue
Block a user