summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/tostring.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-06-19 21:50:33 -0700
committerLance Stout <lancestout@gmail.com>2012-06-19 21:50:33 -0700
commit5820d49cd401a1362a8a675c4b91935adb1240fe (patch)
treef40f78839ae3004bfb0b8da1ae93d61759d8ad66 /sleekxmpp/xmlstream/tostring.py
parent1ab66e576786ecb0cfb9b6b163811735564b951b (diff)
parent36c11ad9de7c1b5a199aa5a4302e33085513c126 (diff)
downloadslixmpp-5820d49cd401a1362a8a675c4b91935adb1240fe.tar.gz
slixmpp-5820d49cd401a1362a8a675c4b91935adb1240fe.tar.bz2
slixmpp-5820d49cd401a1362a8a675c4b91935adb1240fe.tar.xz
slixmpp-5820d49cd401a1362a8a675c4b91935adb1240fe.zip
Merge branch 'master' into develop
Conflicts: sleekxmpp/basexmpp.py
Diffstat (limited to 'sleekxmpp/xmlstream/tostring.py')
-rw-r--r--sleekxmpp/xmlstream/tostring.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/sleekxmpp/xmlstream/tostring.py b/sleekxmpp/xmlstream/tostring.py
index 8e729f79..2480f9b2 100644
--- a/sleekxmpp/xmlstream/tostring.py
+++ b/sleekxmpp/xmlstream/tostring.py
@@ -13,14 +13,19 @@
:license: MIT, see LICENSE for more details
"""
+from __future__ import unicode_literals
+
import sys
if sys.version_info < (3, 0):
import types
+XML_NS = 'http://www.w3.org/XML/1998/namespace'
+
+
def tostring(xml=None, xmlns='', stanza_ns='', stream=None,
- outbuffer='', top_level=False):
+ outbuffer='', top_level=False, open_only=False):
"""Serialize an XML object to a Unicode string.
If namespaces are provided using ``xmlns`` or ``stanza_ns``, then
@@ -88,6 +93,13 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None,
output.append(' %s:%s="%s"' % (mapped_ns,
attrib,
value))
+ elif attrib_ns == XML_NS:
+ output.append(' xml:%s="%s"' % (attrib, value))
+
+ if open_only:
+ # Only output the opening tag, regardless of content.
+ output.append(">")
+ return ''.join(output)
if len(xml) or xml.text:
# If there are additional child elements to serialize.
@@ -95,7 +107,7 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None,
if xml.text:
output.append(xml_escape(xml.text))
if len(xml):
- for child in xml.getchildren():
+ for child in xml:
output.append(tostring(child, tag_xmlns, stanza_ns, stream))
output.append("</%s>" % tag_name)
elif xml.text: