-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decorator #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decorator #231
Conversation
@briancurtin you are involved in the issue previously so I expect your opinion. |
Doc/library/xmlrpc.server.rst
Outdated
@@ -79,14 +79,22 @@ The :class:`SimpleXMLRPCServer` class is based on | |||
alone XML-RPC servers. | |||
|
|||
|
|||
.. method:: SimpleXMLRPCServer.register_function(function, name=None) | |||
.. method:: SimpleXMLRPCServer.register_function(function=None, name=None) | |||
|
|||
Register a function that can respond to XML-RPC requests. If *name* is given, | |||
it will be the method name associated with *function*, otherwise | |||
``function.__name__`` will be used. *name* can be either a normal or Unicode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a normal or Unicode string" -- this is outdated in Python 3.
Doc/library/xmlrpc.server.rst
Outdated
``function.__name__`` will be used. *name* is a string, and may contain | ||
characters not legal in Python identifiers, including the period character. | ||
|
||
From version 3.7, this method can also be used as a decorator. When used as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"From version 3.7" is not needed. There is already a versionchanged directive below.
Doc/library/xmlrpc.server.rst
Outdated
@@ -185,6 +192,37 @@ server:: | |||
# Print list of available methods | |||
print(s.system.listMethods()) | |||
|
|||
Since version 3.7, :meth:`register_function` can also be used as a decorator. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Since version 3.7" is not needed.
Doc/library/xmlrpc.server.rst
Outdated
previous server example can register functions in a decorator way:: | ||
|
||
from xmlrpc.server import SimpleXMLRPCServer | ||
from xmlrpc.server import SimpleXMLRPCRequestHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I'd just merge two imports in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to be consistent with previous examples. I don't want to change this alone. :-)
|
||
# Register a function under a different name, using | ||
# register_function as a decorator. *name* can only be given | ||
# as a keyword argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keyword -> keyword-only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "can only be given as a keyword argument" is same as "keyword-only argument". :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean there is already a shorter way to say the same thing in Python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the term "keyword-only" is applicable only to parameters, not arguments. Parameters can be positional-only (can't be defined in Python syntax), positional-or-keyword or keyword-only. Arguments can be positional or keyword.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the sentence to “*name* is keyword-only". Since *name* is wrapped with asterisks, it's referring to a parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the name parameter is not keyword-only. It is positional-or-keyword.
The former wording looked correct to me, the changed wording don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-(
Doc/library/xmlrpc.server.rst
Outdated
# register_function as a decorator. *name* can only be given | ||
# as a keyword argument. | ||
@server.register_function(name='add') | ||
def adder_function(x,y): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after comma.
Doc/library/xmlrpc.server.rst
Outdated
class RequestHandler(SimpleXMLRPCRequestHandler): | ||
rpc_paths = ('/RPC2',) | ||
|
||
with SimpleXMLRPCServer(("localhost", 8000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Use single quotes to be consistent with the rest of the example.
server.register_introspection_functions() | ||
|
||
# Register pow() function; this will use the value of | ||
# pow.__name__ as the name, which is just 'pow'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name -> *name*?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it's not referring to the parameter here. So just leave it unchanged.
Doc/library/xmlrpc.server.rst
Outdated
``function.__name__`` will be used. *name* is a string, and may contain | ||
characters not legal in Python identifiers, including the period character. | ||
|
||
From version 3.7, this method can also be used as a decorator. When used as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"From version 3.7" is not needed.
Thanks @serhiy-storchaka and @berkerpeksag ! |
(Upstream is https://github.com/python/typing) - Add TYPE_CHECKING (false at runtime, true in type checkers) (upstream python#230). - Avoid error on Union[xml.etree.cElementTree.Element, str] (upstream python#229). - Repr of Tuple[()] should be 'Tuple[()]' (upstream python#231). - Add NewType() (upstream python#189).
Replace "https://bitbucket.org/stackless-dev/stackless" by "https://github.com/stackless-dev/stackless". (cherry picked from commit c11af2f)
Replace "https://bitbucket.org/stackless-dev/stackless" by "https://github.com/stackless-dev/stackless". (cherry picked from commit 49c9417)
open() uses non-binary by default. The equivalent pkg_resources.resource_stream() method opens in binary mode.
No description provided.