简体   繁体   English

什么是python的SimpleXMLRPCServer中的_dispatch()方法

[英]what is a `_dispatch()` method in SimpleXMLRPCServer in python

I was reading the documentation of the register_instance method on SimpleXMLRPCServer. 我正在阅读SimpleXMLRPCServer上register_instance方法的文档。 It has a method signature of: 它具有以下方法签名:

SimpleXMLRPCServer.register_instance(instance[, allow_dotted_names])

and I read about the _dispatch() method: 并且我了解了_dispatch()方法:

If instance contains a _dispatch() method, it is called with the requested method name and the parameters from the request. 如果instance包含_dispatch()方法,则使用请求的方法名称和请求中的参数来调用它。 Its API is def _dispatch(self, method, params) (note that params does not represent a variable argument list). 它的API是def _dispatch(self, method, params) (请注意,params并不表示变量参数列表)。 If it calls an underlying function to perform its task, that function is called as func(*params) , expanding the parameter list. 如果它调用基础函数来执行其任务,则该函数称为func(*params) ,从而扩展参数列表。 The return value from _dispatch() is returned to the client as the result. _dispatch()的返回值作为结果返回给客户端。 If instance does not have a _dispatch() method, it is searched for an attribute matching the name of the requested method 如果实例不具有_dispatch()方法,则会在该实例中搜索与所请求方法名称匹配的属性

What is this _dispatch() method? _dispatch()方法是什么?

I went through the code of SimpleXMLRPCServer and found about the _dispatch method. 我浏览了SimpleXMLRPCServer的代码,发现了有关_dispatch方法的信息。 This is the method to resolve the call to the function on server side when requested by client. 这是在客户端请求时解决对服务器端函数调用的方法。 This is the doc statement - " 这是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."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM