Updated XEP-0009 to handle unicode strings
This commit is contained in:
parent
79f1aa0e1b
commit
31d3e3b2b6
2 changed files with 21 additions and 1 deletions
|
@ -54,7 +54,7 @@ def _py2xml(*args):
|
||||||
boolean = ET.Element("{%s}boolean" % _namespace)
|
boolean = ET.Element("{%s}boolean" % _namespace)
|
||||||
boolean.text = str(int(x))
|
boolean.text = str(int(x))
|
||||||
val.append(boolean)
|
val.append(boolean)
|
||||||
elif type(x) is str:
|
elif type(x) in (str, unicode):
|
||||||
string = ET.Element("{%s}string" % _namespace)
|
string = ET.Element("{%s}string" % _namespace)
|
||||||
string.text = x
|
string.text = x
|
||||||
val.append(string)
|
val.append(string)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- encoding:utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
SleekXMPP: The Sleek XMPP Library
|
SleekXMPP: The Sleek XMPP Library
|
||||||
Copyright (C) 2011 Nathanael C. Fritz, Dann Martens (TOMOTON).
|
Copyright (C) 2011 Nathanael C. Fritz, Dann Martens (TOMOTON).
|
||||||
|
@ -114,6 +116,24 @@ class TestJabberRPC(SleekTest):
|
||||||
self.assertEqual(params, xml2py(expected_xml),
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
"XML to string conversion")
|
"XML to string conversion")
|
||||||
|
|
||||||
|
def testConvertUnicodeString(self):
|
||||||
|
params = [u"おはよう"]
|
||||||
|
params_xml = py2xml(*params)
|
||||||
|
expected_xml = self.parse_xml("""
|
||||||
|
<params xmlns="jabber:iq:rpc">
|
||||||
|
<param>
|
||||||
|
<value>
|
||||||
|
<string>おはよう</string>
|
||||||
|
</value>
|
||||||
|
</param>
|
||||||
|
</params>
|
||||||
|
""")
|
||||||
|
self.assertTrue(self.compare(expected_xml, params_xml),
|
||||||
|
"String to XML conversion\nExpected: %s\nGot: %s" % (
|
||||||
|
tostring(expected_xml), tostring(params_xml)))
|
||||||
|
self.assertEqual(params, xml2py(expected_xml),
|
||||||
|
"XML to string conversion")
|
||||||
|
|
||||||
def testConvertInteger(self):
|
def testConvertInteger(self):
|
||||||
params = [32767, -32768]
|
params = [32767, -32768]
|
||||||
params_xml = py2xml(*params)
|
params_xml = py2xml(*params)
|
||||||
|
|
Loading…
Reference in a new issue