summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2011-12-09 21:35:06 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2011-12-09 21:35:06 (GMT)
commit1b7458b2a1beb86526ab067059ac18a2a0b53cb2 (patch)
tree2fa7c90b22845df99c30d66fb1bcb3871f81f036 /Lib/test
parente3b47152a481313081621b46381384d18d0419e8 (diff)
downloadcpython-1b7458b2a1beb86526ab067059ac18a2a0b53cb2.zip
cpython-1b7458b2a1beb86526ab067059ac18a2a0b53cb2.tar.gz
cpython-1b7458b2a1beb86526ab067059ac18a2a0b53cb2.tar.bz2
Closes #2979: add parameter 'use_builtin_types' to the SimpleXMLRPCServer.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_xmlrpc.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 76723fa..e5601a5 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -1023,10 +1023,44 @@ class CGIHandlerTestCase(unittest.TestCase):
len(content))
+class UseBuiltinTypesTestCase(unittest.TestCase):
+
+ def test_use_builtin_types(self):
+ # SimpleXMLRPCDispatcher.__init__ accepts use_builtin_types, which
+ # makes all dispatch of binary data as bytes instances, and all
+ # dispatch of datetime argument as datetime.datetime instances.
+ self.log = []
+ expected_bytes = b"my dog has fleas"
+ expected_date = datetime.datetime(2008, 5, 26, 18, 25, 12)
+ marshaled = xmlrpclib.dumps((expected_bytes, expected_date), 'foobar')
+ def foobar(*args):
+ self.log.extend(args)
+ handler = xmlrpc.server.SimpleXMLRPCDispatcher(
+ allow_none=True, encoding=None, use_builtin_types=True)
+ handler.register_function(foobar)
+ handler._marshaled_dispatch(marshaled)
+ self.assertEqual(len(self.log), 2)
+ mybytes, mydate = self.log
+ self.assertEqual(self.log, [expected_bytes, expected_date])
+ self.assertIs(type(mydate), datetime.datetime)
+ self.assertIs(type(mybytes), bytes)
+
+ def test_cgihandler_has_use_builtin_types_flag(self):
+ handler = xmlrpc.server.CGIXMLRPCRequestHandler(use_builtin_types=True)
+ self.assertTrue(handler.use_builtin_types)
+
+ def test_xmlrpcserver_has_use_builtin_types_flag(self):
+ server = xmlrpc.server.SimpleXMLRPCServer(("localhost", 0),
+ use_builtin_types=True)
+ server.server_close()
+ self.assertTrue(server.use_builtin_types)
+
+
@support.reap_threads
def test_main():
xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
BinaryTestCase, FaultTestCase]
+ xmlrpc_tests.append(UseBuiltinTypesTestCase)
xmlrpc_tests.append(SimpleServerTestCase)
xmlrpc_tests.append(KeepaliveServerTestCase1)
xmlrpc_tests.append(KeepaliveServerTestCase2)