Skip to content

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

Merged
merged 10 commits into from
Feb 28, 2017

Conversation

zhangyangyu
Copy link
Member

No description provided.

@zhangyangyu
Copy link
Member Author

@briancurtin you are involved in the issue previously so I expect your opinion.

@zhangyangyu zhangyangyu changed the title bpo-7769: enable SimpleXMLRPCServer.SimpleXMLRPCServer.register_function used as decorator bpo-7769: enable SimpleXMLRPCServer.SimpleXMLRPCDispatcher.register_function used as decorator Feb 22, 2017
@zhangyangyu zhangyangyu changed the title bpo-7769: enable SimpleXMLRPCServer.SimpleXMLRPCDispatcher.register_function used as decorator bpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decorator Feb 22, 2017
@@ -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
Copy link
Member

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.

``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
Copy link
Member

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.

@@ -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
Copy link
Member

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.

previous server example can register functions in a decorator way::

from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
Copy link
Member

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.

Copy link
Member Author

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyword -> keyword-only?

Copy link
Member Author

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". :-)

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

@zhangyangyu zhangyangyu Feb 28, 2017

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-(

# register_function as a decorator. *name* can only be given
# as a keyword argument.
@server.register_function(name='add')
def adder_function(x,y):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma.

class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)

with SimpleXMLRPCServer(("localhost", 8000),
Copy link
Member

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'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name -> *name*?

Copy link
Member Author

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.

``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
Copy link
Member

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.

@zhangyangyu zhangyangyu merged commit 267b9d2 into python:master Feb 28, 2017
@zhangyangyu zhangyangyu deleted the xml-register_function branch February 28, 2017 09:13
@zhangyangyu
Copy link
Member Author

Thanks @serhiy-storchaka and @berkerpeksag !

akruis pushed a commit to akruis/cpython that referenced this pull request Oct 18, 2017
(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).
jaraco pushed a commit to jaraco/cpython that referenced this pull request Feb 17, 2023
open() uses non-binary by default.  The equivalent pkg_resources.resource_stream() method opens in binary mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants