0

我正在阅读SimpleXMLRPCServer 上的register_instance方法的文档。它有一个方法签名:

SimpleXMLRPCServer.register_instance(instance[, allow_dotted_names])

我读到了这个_dispatch()方法:

如果实例包含 _dispatch() 方法,则使用请求的方法名称和请求中的参数调用它。它的 API 是def _dispatch(self, method, params)(注意 params 不代表变量参数列表)。如果它调用底层函数来执行其任务,则该函数被称为 as func(*params),扩展参数列表。来自的返回值_dispatch()作为结果返回给客户端。如果实例没有_dispatch()方法,则搜索与请求的方法名称匹配的属性

这是什么_dispatch()方法?

4

1 回答 1

3

我浏览了 SimpleXMLRPCServer 的代码,发现了 _dispatch 方法。这是在客户端请求时解决对服务器端函数的调用的方法。这是文档声明 - “

        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."
于 2013-12-04T08:59:49.063 回答