Skip to content

bpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decorator - #231

Merged
zhangyangyu merged 10 commits into
python:masterfrom
zhangyangyu:xml-register_function
Feb 28, 2017
Merged

bpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decorator#231
zhangyangyu merged 10 commits into
python:masterfrom
zhangyangyu:xml-register_function

Conversation

@zhangyangyu

Copy link
Copy Markdown
Member

No description provided.

@zhangyangyu

Copy link
Copy Markdown
MemberAuthor

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

@zhangyangyuzhangyangyu changed the title bpo-7769: enable SimpleXMLRPCServer.SimpleXMLRPCServer.register_function used as decoratorbpo-7769: enable SimpleXMLRPCServer.SimpleXMLRPCDispatcher.register_function used as decoratorFeb 22, 2017
@zhangyangyuzhangyangyu changed the title bpo-7769: enable SimpleXMLRPCServer.SimpleXMLRPCDispatcher.register_function used as decoratorbpo-7769: enable xmlrpc.server.SimpleXMLRPCDispatcher.register_function used as decoratorFeb 22, 2017
Comment threadDoc/library/xmlrpc.server.rst Outdated

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

Comment threadDoc/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

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.

"From version 3.7" is not needed. There is already a versionchanged directive below.

Comment threadDoc/library/xmlrpc.server.rst Outdated
# 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
Copy Markdown
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
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
MemberAuthor

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
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
MemberAuthor

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.

@zhangyangyuzhangyangyuFeb 28, 2017

Copy link
Copy Markdown
MemberAuthor

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
MemberAuthor

Choose a reason for hiding this comment

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

:-(

Comment threadDoc/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):

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.

Missing space after comma.

Comment threadDoc/library/xmlrpc.server.rst Outdated
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)

with SimpleXMLRPCServer(("localhost", 8000),

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: 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
Copy Markdown
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
Copy Markdown
MemberAuthor

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.

Comment threadDoc/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

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.

"From version 3.7" is not needed.

@zhangyangyu
zhangyangyu merged commit 267b9d2 into python:masterFeb 28, 2017
@zhangyangyu
zhangyangyu deleted the xml-register_function branch February 28, 2017 09:13
@zhangyangyu

Copy link
Copy Markdown
MemberAuthor

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 freeto 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

@zhangyangyu@berkerpeksag@serhiy-storchaka@the-knights-who-say-ni