summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-07-27 18:03:11 (GMT)
committerGuido van Rossum <guido@python.org>2007-07-27 18:03:11 (GMT)
commit3e1f85eb5d20098dd98c941394b2f781dee957d3 (patch)
treed60e53f916c52ea5e363eb13701e478395726254 /Lib/xml
parent3992db81b6c4050a26f7e242b1f16fee245b3127 (diff)
downloadcpython-3e1f85eb5d20098dd98c941394b2f781dee957d3.zip
cpython-3e1f85eb5d20098dd98c941394b2f781dee957d3.tar.gz
cpython-3e1f85eb5d20098dd98c941394b2f781dee957d3.tar.bz2
Fix the minidom test.
In order to do this, I added an optional encoding argument to io.StringIO. The toprettyxml() function returns bytes when you specify an encoding now.
Diffstat (limited to 'Lib/xml')
-rw-r--r--Lib/xml/dom/minidom.py23
1 files changed, 9 insertions, 14 deletions
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py
index 3529bd3..d380022 100644
--- a/Lib/xml/dom/minidom.py
+++ b/Lib/xml/dom/minidom.py
@@ -14,6 +14,7 @@ Todo:
* SAX 2 namespaces
"""
+import io
import xml.dom
from xml.dom import EMPTY_NAMESPACE, EMPTY_PREFIX, XMLNS_NAMESPACE, domreg
@@ -44,20 +45,19 @@ class Node(xml.dom.Node):
def toxml(self, encoding = None):
return self.toprettyxml("", "", encoding)
- def toprettyxml(self, indent="\t", newl="\n", encoding = None):
+ def toprettyxml(self, indent="\t", newl="\n", encoding=None):
# indent = the indentation string to prepend, per level
# newl = the newline string to append
- writer = _get_StringIO()
- if encoding is not None:
- import codecs
- # Can't use codecs.getwriter to preserve 2.0 compatibility
- writer = codecs.lookup(encoding)[3](writer)
+ writer = io.StringIO(encoding=encoding)
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)
- return writer.getvalue()
+ if encoding is None:
+ return writer.getvalue()
+ else:
+ return writer.buffer.getvalue()
def hasChildNodes(self):
if self.childNodes:
@@ -360,7 +360,7 @@ class Attr(Node):
def _get_localName(self):
if 'localName' in self.__dict__:
- return self.__dict__['localName']
+ return self.__dict__['localName']
return self.nodeName.split(":", 1)[-1]
def _get_name(self):
@@ -665,7 +665,7 @@ class Element(Node):
def _get_localName(self):
if 'localName' in self.__dict__:
- return self.__dict__['localName']
+ return self.__dict__['localName']
return self.tagName.split(":", 1)[-1]
def _get_tagName(self):
@@ -1897,11 +1897,6 @@ def _nssplit(qualifiedName):
return (None, fields[0])
-def _get_StringIO():
- # we can't use cStringIO since it doesn't support Unicode strings
- from StringIO import StringIO
- return StringIO()
-
def _do_pulldom_parse(func, args, kwargs):
events = func(*args, **kwargs)
toktype, rootNode = events.getEvent()