From 181aea737d5bce9479795b58c29b5a92da3bd48b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 5 Jun 2012 16:54:26 -0700 Subject: Add initial support for xml:lang for streams and stanza plugins. Remaining items are suitable default actions for language supporting interfaces. --- sleekxmpp/xmlstream/tostring.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sleekxmpp/xmlstream/tostring.py') diff --git a/sleekxmpp/xmlstream/tostring.py b/sleekxmpp/xmlstream/tostring.py index 8e729f79..379ea09a 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. -- cgit v1.2.3 From 7858d969d82eaaa7124b8d59a68c286f06cbf758 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 19 Jun 2012 09:47:31 -0700 Subject: Remove usage of deprecated getchildren() method. --- sleekxmpp/xmlstream/tostring.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sleekxmpp/xmlstream/tostring.py') diff --git a/sleekxmpp/xmlstream/tostring.py b/sleekxmpp/xmlstream/tostring.py index 379ea09a..2480f9b2 100644 --- a/sleekxmpp/xmlstream/tostring.py +++ b/sleekxmpp/xmlstream/tostring.py @@ -107,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("" % tag_name) elif xml.text: -- cgit v1.2.3