mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue 2918: Merge StringIO and cStringIO.
This commit is contained in:
parent
502d89ed15
commit
794652dd06
8 changed files with 702 additions and 22 deletions
|
@ -14,6 +14,7 @@ Todo:
|
|||
* SAX 2 namespaces
|
||||
"""
|
||||
|
||||
import codecs
|
||||
import io
|
||||
import xml.dom
|
||||
|
||||
|
@ -49,16 +50,16 @@ class Node(xml.dom.Node):
|
|||
# indent = the indentation string to prepend, per level
|
||||
# newl = the newline string to append
|
||||
use_encoding = "utf-8" if encoding is None else encoding
|
||||
writer = io.StringIO(encoding=use_encoding)
|
||||
writer = codecs.getwriter(use_encoding)(io.BytesIO())
|
||||
if self.nodeType == Node.DOCUMENT_NODE:
|
||||
# Can pass encoding only to document, to put it into XML header
|
||||
self.writexml(writer, "", indent, newl, encoding)
|
||||
else:
|
||||
self.writexml(writer, "", indent, newl)
|
||||
if encoding is None:
|
||||
return writer.getvalue()
|
||||
return writer.stream.getvalue().decode(use_encoding)
|
||||
else:
|
||||
return writer.buffer.getvalue()
|
||||
return writer.stream.getvalue()
|
||||
|
||||
def hasChildNodes(self):
|
||||
if self.childNodes:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue