我正在阅读SimpleXMLRPCServer上register_instance方法的文档。它的方法签名为:
SimpleXMLRPCServer.register_instance(instance[, allow_dotted_names])
我读到了_dispatch()
方法:
如果实例包含_dispatch()方法,则使用请求的方法名称和请求中的参数调用它。它的API是
def _dispatch(self, method, params)
(请注意,params不代表变量参数列表)。如果它调用底层函数来执行其任务,则该函数被调用为func(*params)
,扩展参数列表。作为结果,_dispatch()
的返回值将返回给客户端。如果实例没有_dispatch()
方法,则会搜索与所请求方法名称匹配的属性
这个_dispatch()
方法是什么?
答案 0 :(得分:3)
我浏览了SimpleXMLRPCServer的代码,发现了_dispatch方法。这是在客户端请求时解析对服务器端函数的调用的方法。这是doc声明 - “
XML-RPC calls are forwarded to a registered function that
matches the called XML-RPC method name. If no such function
exists then the call is forwarded to the registered instance,
if available.
If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))
If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called.
Methods beginning with an '_' are considered private and will
not be called."