Visitar URL original
bpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decorator by zhangyangyu · Pull Request #231 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix style nits
  • Loading branch information
zhangyangyu committed Feb 28, 2017
commit eaa27d9d17aa0e2818e3b90e5ca6e3136165fc83
26 changes: 12 additions & 14 deletions Doc/library/xmlrpc.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ alone XML-RPC servers.
``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
a decorator, *name* can be given as a keyword-only argument to register
*function* under *name*. If no *name* is given, ``function.__name__`` will be
used.
This method can also be used as a decorator. When used as a decorator,
*name* can be given as a keyword-only argument to register *function* under
*name*. If no *name* is given, ``function.__name__`` will be used.

.. versionchanged:: 3.7
:meth:`register_function` can be used as a decorator.
Expand Down Expand Up @@ -155,7 +154,7 @@ Server code::
rpc_paths = ('/RPC2',)

# Create server
with SimpleXMLRPCServer(("localhost", 8000),
with SimpleXMLRPCServer(('localhost', 8000),
requestHandler=RequestHandler) as server:
server.register_introspection_functions()

Expand All @@ -164,7 +163,7 @@ Server code::
server.register_function(pow)

# Register a function under a different name
def adder_function(x,y):
def adder_function(x, y):
return x + y
server.register_function(adder_function, 'add')

Expand Down Expand Up @@ -192,16 +191,16 @@ 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
previous server example can register functions in a decorator way::
:meth:`register_function` can also be used as a decorator. The previous server
example can register functions in a decorator way::

from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler

Copy link
Copy Markdown
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
Copy Markdown
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. :-)


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

with SimpleXMLRPCServer(("localhost", 8000),
with SimpleXMLRPCServer(('localhost', 8000),
requestHandler=RequestHandler) as server:
server.register_introspection_functions()

Expand All @@ -213,7 +212,7 @@ previous server example can register functions in a decorator way::
# register_function as a decorator. *name* can only be given
# as a keyword argument.

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

@zhangyangyu zhangyangyu Feb 28, 2017 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

:-(

@server.register_function(name='add')
def adder_function(x,y):
def adder_function(x, y):
return x + y

# Register a function under function.__name__.
Expand Down Expand Up @@ -301,10 +300,9 @@ requests sent to Python CGI scripts.
``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
a decorator, *name* can be given as a keyword-only argument to register
*function* under *name*. If no *name* is given, ``function.__name__`` will be
used.
This method can also be used as a decorator. When used as a decorator,
*name* can be given as a keyword-only argument to register *function* under
*name*. If no *name* is given, ``function.__name__`` will be used.

.. versionchanged:: 3.7
:meth:`register_function` can be used as a decorator.
Expand Down