py3: Get rid of the last cStringIO

This commit is contained in:
Kovid Goyal 2019-04-01 18:42:25 +05:30
parent d59d91374a
commit 9b3e525610
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 6 deletions

View File

@ -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']))

View File

@ -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()