@@ -183,6 +183,20 @@ def test_dump_none(self):
183
183
xmlrpclib .loads (strg )[0 ][0 ])
184
184
self .assertRaises (TypeError , xmlrpclib .dumps , (arg1 ,))
185
185
186
+ def test_dump_encoding (self ):
187
+ value = '\u20ac '
188
+ strg = xmlrpclib .dumps ((value ,), encoding = 'iso-8859-15' )
189
+ strg = "<?xml version='1.0' encoding='iso-8859-15'?>" + strg
190
+ self .assertEqual (xmlrpclib .loads (strg )[0 ][0 ], value )
191
+ strg = strg .encode ('iso-8859-15' )
192
+ self .assertEqual (xmlrpclib .loads (strg )[0 ][0 ], value )
193
+
194
+ strg = xmlrpclib .dumps ((value ,), encoding = 'iso-8859-15' ,
195
+ methodresponse = True )
196
+ self .assertEqual (xmlrpclib .loads (strg )[0 ][0 ], value )
197
+ strg = strg .encode ('iso-8859-15' )
198
+ self .assertEqual (xmlrpclib .loads (strg )[0 ][0 ], value )
199
+
186
200
def test_dump_bytes (self ):
187
201
sample = b"my dog has fleas"
188
202
self .assertEqual (sample , xmlrpclib .Binary (sample ))
@@ -371,7 +385,7 @@ def test_decode(self):
371
385
# The evt is set twice. First when the server is ready to serve.
372
386
# Second when the server has been shutdown. The user must clear
373
387
# the event after it has been set the first time to catch the second set.
374
- def http_server (evt , numrequests , requestHandler = None ):
388
+ def http_server (evt , numrequests , requestHandler = None , encoding = None ):
375
389
class TestInstanceClass :
376
390
def div (self , x , y ):
377
391
return x // y
@@ -400,6 +414,7 @@ def get_request(self):
400
414
if not requestHandler :
401
415
requestHandler = xmlrpc .server .SimpleXMLRPCRequestHandler
402
416
serv = MyXMLRPCServer (("localhost" , 0 ), requestHandler ,
417
+ encoding = encoding ,
403
418
logRequests = False , bind_and_activate = False )
404
419
try :
405
420
serv .server_bind ()
@@ -582,6 +597,20 @@ def test_nonascii(self):
582
597
# protocol error; provide additional information in test output
583
598
self .fail ("%s\n %s" % (e , getattr (e , "headers" , "" )))
584
599
600
+ def test_client_encoding (self ):
601
+ start_string = '\u20ac '
602
+ end_string = '\xa3 '
603
+
604
+ try :
605
+ p = xmlrpclib .ServerProxy (URL , encoding = 'iso-8859-15' )
606
+ self .assertEqual (p .add (start_string , end_string ),
607
+ start_string + end_string )
608
+ except (xmlrpclib .ProtocolError , socket .error ) as e :
609
+ # ignore failures due to non-blocking socket unavailable errors.
610
+ if not is_unavailable_exception (e ):
611
+ # protocol error; provide additional information in test output
612
+ self .fail ("%s\n %s" % (e , getattr (e , "headers" , "" )))
613
+
585
614
# [ch] The test 404 is causing lots of false alarms.
586
615
def XXXtest_404 (self ):
587
616
# send POST with http.client, it should return 404 header and
@@ -731,6 +760,26 @@ def test_context_manager_method_error(self):
731
760
(None , None ))
732
761
733
762
763
+ class SimpleServerEncodingTestCase (BaseServerTestCase ):
764
+ @staticmethod
765
+ def threadFunc (evt , numrequests , requestHandler = None , encoding = None ):
766
+ http_server (evt , numrequests , requestHandler , 'iso-8859-15' )
767
+
768
+ def test_server_encoding (self ):
769
+ start_string = '\u20ac '
770
+ end_string = '\xa3 '
771
+
772
+ try :
773
+ p = xmlrpclib .ServerProxy (URL )
774
+ self .assertEqual (p .add (start_string , end_string ),
775
+ start_string + end_string )
776
+ except (xmlrpclib .ProtocolError , socket .error ) as e :
777
+ # ignore failures due to non-blocking socket unavailable errors.
778
+ if not is_unavailable_exception (e ):
779
+ # protocol error; provide additional information in test output
780
+ self .fail ("%s\n %s" % (e , getattr (e , "headers" , "" )))
781
+
782
+
734
783
class MultiPathServerTestCase (BaseServerTestCase ):
735
784
threadFunc = staticmethod (http_multi_server )
736
785
request_count = 2
@@ -1143,8 +1192,9 @@ def test_xmlrpcserver_has_use_builtin_types_flag(self):
1143
1192
def test_main ():
1144
1193
support .run_unittest (XMLRPCTestCase , HelperTestCase , DateTimeTestCase ,
1145
1194
BinaryTestCase , FaultTestCase , UseBuiltinTypesTestCase ,
1146
- SimpleServerTestCase , KeepaliveServerTestCase1 ,
1147
- KeepaliveServerTestCase2 , GzipServerTestCase , GzipUtilTestCase ,
1195
+ SimpleServerTestCase , SimpleServerEncodingTestCase ,
1196
+ KeepaliveServerTestCase1 , KeepaliveServerTestCase2 ,
1197
+ GzipServerTestCase , GzipUtilTestCase ,
1148
1198
MultiPathServerTestCase , ServerProxyTestCase , FailingServerTestCase ,
1149
1199
CGIHandlerTestCase )
1150
1200
0 commit comments