diff -r 18f1012e0c56 Doc/library/xmlrpc.server.rst --- a/Doc/library/xmlrpc.server.rst Fri Jun 10 14:26:32 2016 +0300 +++ b/Doc/library/xmlrpc.server.rst Wed Jun 15 23:15:49 2016 +0800 @@ -86,6 +86,9 @@ string, and may contain characters not legal in Python identifiers, including the period character. + .. versionadded:: 3.6 + :meth:`register_function` can be used as a decorator now. + .. method:: SimpleXMLRPCServer.register_instance(instance, allow_dotted_names=False) diff -r 18f1012e0c56 Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py Fri Jun 10 14:26:32 2016 +0300 +++ b/Lib/test/test_xmlrpc.py Wed Jun 15 23:15:49 2016 +0800 @@ -456,10 +456,6 @@ def getData(): return '42' - def my_function(): - '''This is my function''' - return True - class MyXMLRPCServer(xmlrpc.server.SimpleXMLRPCServer): def get_request(self): # Ensure the socket is always non-blocking. On Linux, socket @@ -486,9 +482,14 @@ serv.register_introspection_functions() serv.register_multicall_functions() serv.register_function(pow) - serv.register_function(lambda x,y: x+y, 'add') serv.register_function(lambda x: x, 'têšt') - serv.register_function(my_function) + @serv.register_function + def my_function(): + '''This is my function''' + return True + @serv.register_function(name='add') + def _(x, y): + return x + y testInstance = TestInstanceClass() serv.register_instance(testInstance, allow_dotted_names=True) evt.set() diff -r 18f1012e0c56 Lib/xmlrpc/server.py --- a/Lib/xmlrpc/server.py Fri Jun 10 14:26:32 2016 +0300 +++ b/Lib/xmlrpc/server.py Wed Jun 15 23:15:49 2016 +0800 @@ -106,6 +106,7 @@ from xmlrpc.client import Fault, dumps, loads, gzip_encode, gzip_decode from http.server import BaseHTTPRequestHandler +from functools import partial import http.server import socketserver import sys @@ -204,17 +205,22 @@ self.instance = instance self.allow_dotted_names = allow_dotted_names - def register_function(self, function, name=None): + def register_function(self, function=None, name=None): """Registers a function to respond to XML-RPC requests. The optional name argument can be used to set a Unicode name for the function. """ + # decorator factory + if function is None: + return partial(self.register_function, name=name) if name is None: name = function.__name__ self.funcs[name] = function + return function + def register_introspection_functions(self): """Registers the XML-RPC introspection methods in the system namespace.