summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-03-19 14:06:36 -0700
committerLance Stout <lancestout@gmail.com>2012-03-19 14:06:36 -0700
commit3acc7d0914eb1ad883caf6a39685a807a17ba75c (patch)
tree69d0f4b23db5ef9955cb6de4971b61a968615920
parentb077ef91502c2e723afe5e0130c85103b0118648 (diff)
parent31d3e3b2b640e210e577eaa01c292c92be84d953 (diff)
downloadslixmpp-3acc7d0914eb1ad883caf6a39685a807a17ba75c.tar.gz
slixmpp-3acc7d0914eb1ad883caf6a39685a807a17ba75c.tar.bz2
slixmpp-3acc7d0914eb1ad883caf6a39685a807a17ba75c.tar.xz
slixmpp-3acc7d0914eb1ad883caf6a39685a807a17ba75c.zip
Merge pull request #150 from correl/rpc_value_fixes
Updated XEP-0009 to handle unicode strings
-rw-r--r--sleekxmpp/plugins/xep_0009/binding.py2
-rw-r--r--tests/test_stanza_xep_0009.py20
2 files changed, 21 insertions, 1 deletions
diff --git a/sleekxmpp/plugins/xep_0009/binding.py b/sleekxmpp/plugins/xep_0009/binding.py
index 2b16a0c0..5418626b 100644
--- a/sleekxmpp/plugins/xep_0009/binding.py
+++ b/sleekxmpp/plugins/xep_0009/binding.py
@@ -54,7 +54,7 @@ def _py2xml(*args):
boolean = ET.Element("{%s}boolean" % _namespace)
boolean.text = str(int(x))
val.append(boolean)
- elif type(x) is str:
+ elif type(x) in (str, unicode):
string = ET.Element("{%s}string" % _namespace)
string.text = x
val.append(string)
diff --git a/tests/test_stanza_xep_0009.py b/tests/test_stanza_xep_0009.py
index 36800335..724ebb95 100644
--- a/tests/test_stanza_xep_0009.py
+++ b/tests/test_stanza_xep_0009.py
@@ -1,3 +1,5 @@
+# -*- encoding:utf-8 -*-
+
"""
SleekXMPP: The Sleek XMPP Library
Copyright (C) 2011 Nathanael C. Fritz, Dann Martens (TOMOTON).
@@ -114,6 +116,24 @@ class TestJabberRPC(SleekTest):
self.assertEqual(params, xml2py(expected_xml),
"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):
params = [32767, -32768]
params_xml = py2xml(*params)