diff -r ed011b0d7daf Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py Sun Sep 22 16:18:19 2013 -0700 +++ b/Lib/test/test_xmlrpc.py Mon Sep 23 14:25:03 2013 +0800 @@ -380,6 +380,9 @@ if name == 'div': return 'This is the div function' + def sophisticated_function(x, y, z=1, *args, **kwargs): + pass + def my_function(): '''This is my function''' return True @@ -411,6 +414,7 @@ serv.register_function(pow) serv.register_function(lambda x,y: x+y, 'add') serv.register_function(my_function) + serv.register_function(sophisticated_function) serv.register_instance(TestInstanceClass()) evt.set() @@ -590,8 +594,9 @@ def test_introspection1(self): expected_methods = set(['pow', 'div', 'my_function', 'add', - 'system.listMethods', 'system.methodHelp', - 'system.methodSignature', 'system.multicall']) + 'sophisticated_function', 'system.listMethods', + 'system.methodHelp', 'system.methodSignature', + 'system.multicall']) try: p = xmlrpclib.ServerProxy(URL) meth = p.system.listMethods() @@ -630,12 +635,21 @@ self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) def test_introspection4(self): - # the SimpleXMLRPCServer doesn't support signatures, but - # at least check that we can try making the call try: p = xmlrpclib.ServerProxy(URL) - divsig = p.system.methodSignature('div') - self.assertEqual(divsig, 'signatures not supported') + sophissig = p.system.methodSignature('sophisticated_function') + self.assertEqual(sophissig, '(x, y, z=1, *args, **kwargs)') + except (xmlrpclib.ProtocolError, OSError) as e: + # ignore failures due to non-blocking socket 'unavailable' errors + if not is_unavailable_exception(e): + # protocol error; provide additional information in test output + self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) + + def test_introspection5(self): + try: + p = xmlrpclib.ServerProxy(URL) + self.assertRaises(xmlrpclib.Fault, p.system.methodSignature, + 'bogus_function') except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors if not is_unavailable_exception(e): diff -r ed011b0d7daf Lib/xmlrpc/server.py --- a/Lib/xmlrpc/server.py Sun Sep 22 16:18:19 2013 -0700 +++ b/Lib/xmlrpc/server.py Mon Sep 23 14:25:03 2013 +0800 @@ -290,17 +290,16 @@ return sorted(methods) def system_methodSignature(self, method_name): - """system.methodSignature('add') => [double, int, int] + """system.methodSignature('add') => '(x, y)' Returns a list describing the signature of the method. In the - above example, the add method takes two integers as arguments - and returns a double result. + above example, the add method takes two variables as arguments.""" - This server does NOT support system.methodSignature.""" - - # See http://xmlrpc.usefulinc.com/doc/sysmethodsig.html - - return 'signatures not supported' + try: + func = self.funcs[method_name] + return str(inspect.signature(func)) + except KeyError: + raise Exception('method "%s" can not be found' % method_name) def system_methodHelp(self, method_name): """system.methodHelp('add') => "Adds two integers together"