Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: Lib/test/test_xmlrpc.py

Issue 26147: Encoding errors in xmlrpc
Patch Set: Created 4 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/xmlrpclib.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import base64 1 import base64
2 import datetime 2 import datetime
3 import sys 3 import sys
4 import time 4 import time
5 import unittest 5 import unittest
6 import xmlrpclib 6 import xmlrpclib
7 import SimpleXMLRPCServer 7 import SimpleXMLRPCServer
8 import mimetools 8 import mimetools
9 import httplib 9 import httplib
10 import socket 10 import socket
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 def test_dump_none(self): 142 def test_dump_none(self):
143 value = alist + [None] 143 value = alist + [None]
144 arg1 = (alist + [None],) 144 arg1 = (alist + [None],)
145 strg = xmlrpclib.dumps(arg1, allow_none=True) 145 strg = xmlrpclib.dumps(arg1, allow_none=True)
146 self.assertEqual(value, 146 self.assertEqual(value,
147 xmlrpclib.loads(strg)[0][0]) 147 xmlrpclib.loads(strg)[0][0])
148 self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,)) 148 self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
149 149
150 @test_support.requires_unicode 150 @test_support.requires_unicode
151 def test_dump_encoding(self): 151 def test_dump_encoding(self):
152 value = unichr(0x20ac) 152 value = unichr(0x20ac) + unichr(0xa4)
153 strg = xmlrpclib.dumps((value,), encoding='iso-8859-15') 153 strg = xmlrpclib.dumps((value,), encoding='iso-8859-15')
154 strg = "<?xml version='1.0' encoding='iso-8859-15'?>" + strg 154 strg = "<?xml version='1.0' encoding='iso-8859-15'?>" + strg
155 self.assertEqual(xmlrpclib.loads(strg)[0][0], value) 155 self.assertEqual(xmlrpclib.loads(strg)[0][0], value)
156 156
157 strg = xmlrpclib.dumps((value,), encoding='iso-8859-15', 157 strg = xmlrpclib.dumps((value,), encoding='iso-8859-15',
158 methodresponse=True) 158 methodresponse=True)
159 self.assertEqual(xmlrpclib.loads(strg)[0][0], value) 159 self.assertEqual(xmlrpclib.loads(strg)[0][0], value)
160 160
161 @test_support.requires_unicode 161 @test_support.requires_unicode
162 def test_default_encoding_issues(self): 162 def test_default_encoding_issues(self):
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 489 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
490 490
491 @test_support.requires_unicode 491 @test_support.requires_unicode
492 def test_unicode_host(self): 492 def test_unicode_host(self):
493 server = xmlrpclib.ServerProxy(u"http://%s:%d/RPC2"%(ADDR, PORT)) 493 server = xmlrpclib.ServerProxy(u"http://%s:%d/RPC2"%(ADDR, PORT))
494 self.assertEqual(server.add("a", u"\xe9"), u"a\xe9") 494 self.assertEqual(server.add("a", u"\xe9"), u"a\xe9")
495 495
496 @test_support.requires_unicode 496 @test_support.requires_unicode
497 def test_client_encoding(self): 497 def test_client_encoding(self):
498 start_string = unichr(0x20ac) 498 start_string = unichr(0x20ac)
499 end_string = unichr(0xa3) 499 end_string = unichr(0xa4)
500 500
501 try: 501 try:
502 p = xmlrpclib.ServerProxy(URL, encoding='iso-8859-15') 502 p = xmlrpclib.ServerProxy(URL, encoding='iso-8859-15')
503 self.assertEqual(p.add(start_string, end_string), 503 self.assertEqual(p.add(start_string, end_string),
504 start_string + end_string) 504 start_string + end_string)
505 except (xmlrpclib.ProtocolError, socket.error) as e: 505 except (xmlrpclib.ProtocolError, socket.error) as e:
506 # ignore failures due to non-blocking socket unavailable errors. 506 # ignore failures due to non-blocking socket unavailable errors.
507 if not is_unavailable_exception(e): 507 if not is_unavailable_exception(e):
508 # protocol error; provide additional information in test output 508 # protocol error; provide additional information in test output
509 self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 509 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 conn.close() 628 conn.close()
629 629
630 class SimpleServerEncodingTestCase(BaseServerTestCase): 630 class SimpleServerEncodingTestCase(BaseServerTestCase):
631 @staticmethod 631 @staticmethod
632 def threadFunc(evt, numrequests, requestHandler=None, encoding=None): 632 def threadFunc(evt, numrequests, requestHandler=None, encoding=None):
633 http_server(evt, numrequests, requestHandler, 'iso-8859-15') 633 http_server(evt, numrequests, requestHandler, 'iso-8859-15')
634 634
635 @test_support.requires_unicode 635 @test_support.requires_unicode
636 def test_server_encoding(self): 636 def test_server_encoding(self):
637 start_string = unichr(0x20ac) 637 start_string = unichr(0x20ac)
638 end_string = unichr(0xa3) 638 end_string = unichr(0xa4)
639 639
640 try: 640 try:
641 p = xmlrpclib.ServerProxy(URL) 641 p = xmlrpclib.ServerProxy(URL)
642 self.assertEqual(p.add(start_string, end_string), 642 self.assertEqual(p.add(start_string, end_string),
643 start_string + end_string) 643 start_string + end_string)
644 except (xmlrpclib.ProtocolError, socket.error) as e: 644 except (xmlrpclib.ProtocolError, socket.error) as e:
645 # ignore failures due to non-blocking socket unavailable errors. 645 # ignore failures due to non-blocking socket unavailable errors.
646 if not is_unavailable_exception(e): 646 if not is_unavailable_exception(e):
647 # protocol error; provide additional information in test output 647 # protocol error; provide additional information in test output
648 self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) 648 self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 xmlrpc_tests.append(GzipServerTestCase) 1086 xmlrpc_tests.append(GzipServerTestCase)
1087 xmlrpc_tests.append(MultiPathServerTestCase) 1087 xmlrpc_tests.append(MultiPathServerTestCase)
1088 xmlrpc_tests.append(ServerProxyTestCase) 1088 xmlrpc_tests.append(ServerProxyTestCase)
1089 xmlrpc_tests.append(FailingServerTestCase) 1089 xmlrpc_tests.append(FailingServerTestCase)
1090 xmlrpc_tests.append(CGIHandlerTestCase) 1090 xmlrpc_tests.append(CGIHandlerTestCase)
1091 1091
1092 test_support.run_unittest(*xmlrpc_tests) 1092 test_support.run_unittest(*xmlrpc_tests)
1093 1093
1094 if __name__ == "__main__": 1094 if __name__ == "__main__":
1095 test_main() 1095 test_main()
OLDNEW
« no previous file with comments | « no previous file | Lib/xmlrpclib.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+