summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/tostring
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-12-07 23:07:40 -0500
committerLance Stout <lancestout@gmail.com>2010-12-07 23:07:40 -0500
commitf474d378efdc754b57dedd60a9905ac5e75ee55d (patch)
treeeba26755fdc0fb55ceddb0bde01fd5c77795775d /sleekxmpp/xmlstream/tostring
parentdefc252c7dabb1d54fe20b3ac8661d0198ff40bd (diff)
downloadslixmpp-f474d378efdc754b57dedd60a9905ac5e75ee55d.tar.gz
slixmpp-f474d378efdc754b57dedd60a9905ac5e75ee55d.tar.bz2
slixmpp-f474d378efdc754b57dedd60a9905ac5e75ee55d.tar.xz
slixmpp-f474d378efdc754b57dedd60a9905ac5e75ee55d.zip
Add support for using xml:lang values.
Support is only for adding literal XML content to stanzas. Full support for things like multiple message bodies with different xml:lang values is still in the works.
Diffstat (limited to 'sleekxmpp/xmlstream/tostring')
-rw-r--r--sleekxmpp/xmlstream/tostring/tostring.py13
-rw-r--r--sleekxmpp/xmlstream/tostring/tostring26.py15
2 files changed, 23 insertions, 5 deletions
diff --git a/sleekxmpp/xmlstream/tostring/tostring.py b/sleekxmpp/xmlstream/tostring/tostring.py
index d8f5c5b2..38b08d82 100644
--- a/sleekxmpp/xmlstream/tostring/tostring.py
+++ b/sleekxmpp/xmlstream/tostring/tostring.py
@@ -52,9 +52,18 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None, outbuffer=''):
# Output escaped attribute values.
for attrib, value in xml.attrib.items():
- if '{' not in attrib:
- value = xml_escape(value)
+ value = xml_escape(value)
+ if '}' not in attrib:
output.append(' %s="%s"' % (attrib, value))
+ else:
+ attrib_ns = attrib.split('}')[0][1:]
+ attrib = attrib.split('}')[1]
+ if stream and attrib_ns in stream.namespace_map:
+ mapped_ns = stream.namespace_map[attrib_ns]
+ if mapped_ns:
+ output.append(' %s:%s="%s"' % (mapped_ns,
+ attrib,
+ value))
if len(xml) or xml.text:
# If there are additional child elements to serialize.
diff --git a/sleekxmpp/xmlstream/tostring/tostring26.py b/sleekxmpp/xmlstream/tostring/tostring26.py
index 0ee432cc..11501780 100644
--- a/sleekxmpp/xmlstream/tostring/tostring26.py
+++ b/sleekxmpp/xmlstream/tostring/tostring26.py
@@ -55,9 +55,18 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None, outbuffer=''):
# Output escaped attribute values.
for attrib, value in xml.attrib.items():
- if '{' not in attrib:
- value = xml_escape(value)
- output.append(u' %s="%s"' % (attrib, value))
+ value = xml_escape(value)
+ if '}' not in attrib:
+ output.append(' %s="%s"' % (attrib, value))
+ else:
+ attrib_ns = attrib.split('}')[0][1:]
+ attrib = attrib.split('}')[1]
+ if stream and attrib_ns in stream.namespace_map:
+ mapped_ns = stream.namespace_map[attrib_ns]
+ if mapped_ns:
+ output.append(' %s:%s="%s"' % (mapped_ns,
+ attrib,
+ value))
if len(xml) or xml.text:
# If there are additional child elements to serialize.