[Python-checkins] python/dist/src/Lib/test test_xmlrpc.py,1.6,1.7
fdrake at users.sourceforge.net
fdrake at users.sourceforge.net
Fri Feb 11 18:59:24 CET 2005
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18158/Lib/test
Modified Files:
test_xmlrpc.py
Log Message:
fix decoding in _stringify to not depend on the default encoding
(closes SF bug #1115989)
Index: test_xmlrpc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_xmlrpc.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- test_xmlrpc.py 10 Feb 2005 18:33:30 -0000 1.6
+++ test_xmlrpc.py 11 Feb 2005 17:59:08 -0000 1.7
@@ -4,6 +4,13 @@
import xmlrpclib
from test import test_support
+try:
+ unicode
+except NameError:
+ have_unicode = False
+else:
+ have_unicode = True
+
alist = [{'astring': 'foo at bar.baz.spam',
'afloat': 7283.43,
'anint': 2**20,
@@ -56,6 +63,41 @@
xmlrpclib.loads(strg)[0][0])
self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
+ def test_default_encoding_issues(self):
+ # SF bug #1115989: wrong decoding in '_stringify'
+ utf8 = """<?xml version='1.0' encoding='iso-8859-1'?>
+ <params>
+ <param><value>
+ <string>abc \x95</string>
+ </value></param>
+ <param><value>
+ <struct>
+ <member>
+ <name>def \x96</name>
+ <value><string>ghi \x97</string></value>
+ </member>
+ </struct>
+ </value></param>
+ </params>
+ """
+ old_encoding = sys.getdefaultencoding()
+ reload(sys) # ugh!
+ sys.setdefaultencoding("iso-8859-1")
+ try:
+ (s, d), m = xmlrpclib.loads(utf8)
+ finally:
+ sys.setdefaultencoding(old_encoding)
+ items = d.items()
+ if have_unicode:
+ self.assertEquals(s, u"abc \x95")
+ self.assert_(isinstance(s, unicode))
+ self.assertEquals(items, [(u"def \x96", u"ghi \x97")])
+ self.assert_(isinstance(items[0][0], unicode))
+ self.assert_(isinstance(items[0][1], unicode))
+ else:
+ self.assertEquals(s, "abc \xc2\x95")
+ self.assertEquals(items, [("def \xc2\x96", "ghi \xc2\x97")])
+
def test_main():
test_support.run_unittest(XMLRPCTestCase)
More information about the Python-checkins
mailing list