diff options
author | Lance Stout <lancestout@gmail.com> | 2012-09-25 02:45:48 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-09-25 02:45:48 -0700 |
commit | 73ce9a5eccb5fea6f9a6dd72410cdada2a43347f (patch) | |
tree | 8589f9f5e8c0730152779fc57c6a7d178a1cfb3b /sleekxmpp/xmlstream/tostring.py | |
parent | d385b9e708e9e8904ed9a19ac01096c50d521eff (diff) | |
parent | 671f680bb39f366ad13bf937c7b611f667343314 (diff) | |
download | slixmpp-73ce9a5eccb5fea6f9a6dd72410cdada2a43347f.tar.gz slixmpp-73ce9a5eccb5fea6f9a6dd72410cdada2a43347f.tar.bz2 slixmpp-73ce9a5eccb5fea6f9a6dd72410cdada2a43347f.tar.xz slixmpp-73ce9a5eccb5fea6f9a6dd72410cdada2a43347f.zip |
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/xmlstream/tostring.py')
-rw-r--r-- | sleekxmpp/xmlstream/tostring.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/sleekxmpp/xmlstream/tostring.py b/sleekxmpp/xmlstream/tostring.py index f22e7770..0b73d8dc 100644 --- a/sleekxmpp/xmlstream/tostring.py +++ b/sleekxmpp/xmlstream/tostring.py @@ -24,19 +24,18 @@ if sys.version_info < (3, 0): XML_NS = 'http://www.w3.org/XML/1998/namespace' -def tostring(xml=None, xmlns='', stanza_ns='', stream=None, +def tostring(xml=None, xmlns='', stream=None, 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 - elements that use those namespaces will not include the xmlns attribute - in the output. + If an outer xmlns is provided using ``xmlns``, then the current element's + namespace will not be included if it matches the outer namespace. An + exception is made for elements that have an attached stream, and appear + at the stream root. :param XML xml: The XML object to serialize. :param string xmlns: Optional namespace of an element wrapping the XML object. - :param string stanza_ns: The namespace of the stanza object that contains - the XML object. :param stream: The XML stream that generated the XML object. :param string outbuffer: Optional buffer for storing serializations during recursive calls. @@ -71,8 +70,8 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None, # Output the tag name and derived namespace of the element. namespace = '' - if top_level and tag_xmlns not in ['', default_ns, stream_ns] or \ - tag_xmlns not in ['', xmlns, stanza_ns, stream_ns]: + if top_level and tag_xmlns not in [default_ns, xmlns, stream_ns] \ + or not top_level and tag_xmlns != xmlns: namespace = ' xmlns="%s"' % tag_xmlns if stream and tag_xmlns in stream.namespace_map: mapped_namespace = stream.namespace_map[tag_xmlns] @@ -110,7 +109,7 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None, output.append(escape(xml.text, use_cdata)) if len(xml): for child in xml: - output.append(tostring(child, tag_xmlns, stanza_ns, stream)) + output.append(tostring(child, tag_xmlns, stream)) output.append("</%s>" % tag_name) elif xml.text: # If we only have text content. |