diff options
author | Xiang Zhang <angwerzx@126.com> | 2017-02-28 09:12:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 09:12:52 (GMT) |
commit | 267b9d2fa8efce7c5bc34ce50048ebca8fddf04f (patch) | |
tree | b35a09c9064f25d825c721dc29b18e5bf94143f5 /Lib/xmlrpc | |
parent | 7c8b3fa31caf866572649e2bc82729d8fc081b89 (diff) | |
download | cpython-267b9d2fa8efce7c5bc34ce50048ebca8fddf04f.zip cpython-267b9d2fa8efce7c5bc34ce50048ebca8fddf04f.tar.gz cpython-267b9d2fa8efce7c5bc34ce50048ebca8fddf04f.tar.bz2 |
bpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decorator (GH-231)
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r-- | Lib/xmlrpc/server.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py index 849bfdd..a6275a1 100644 --- a/Lib/xmlrpc/server.py +++ b/Lib/xmlrpc/server.py @@ -106,6 +106,7 @@ server.handle_request() 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 @@ class SimpleXMLRPCDispatcher: 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. |