pythonsimplexmlrpcserver

what is a `_dispatch()` method in SimpleXMLRPCServer in python


I was reading the documentation of the register_instance method on SimpleXMLRPCServer. It has a method signature of:

SimpleXMLRPCServer.register_instance(instance[, allow_dotted_names])

and I read about the _dispatch() method:

If instance contains a _dispatch() method, it is called with the requested method name and the parameters from the request. Its API is def _dispatch(self, method, params) (note that params does not represent a variable argument list). If it calls an underlying function to perform its task, that function is called as func(*params), expanding the parameter list. The return value from _dispatch() is returned to the client as the result. If instance does not have a _dispatch() method, it is searched for an attribute matching the name of the requested method

What is this _dispatch() method?


Solution

  • I went through the code of SimpleXMLRPCServer and found about the _dispatch method. This is the method to resolve the call to the function on server side when requested by client. This is the doc statement - "

            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."