Name

register_instance

Synopsis

                           x.register_instance(inst)

Registers inst to respond to XML-RPC requests with names not registered via register_function. When inst supplies a method _dispatch, inst ._dispatch is called with the request’s name and parameters as arguments. When inst does not supply _dispatch, the request’s name is used as an attribute name to search on inst. When the request’s name contains dots, the search repeats recursively for each component. The attribute found by this search is then called with the request’s parameters as arguments. Only one instance at a time can be registered with register_instance: if you call x .register_instance again, the instance passed in the previous call to x .register_instance is replaced by the one passed in the later call.

Simple examples of all typical usage patterns for impleXMLRPCServer are given in the docstring of module SimpleXMLRPCServer.py, which you can find in the Lib directory of your Python installation (Python 2.2 and later only). Here is a toy example of using the _dispatch method. In one terminal window, run the following tiny script:

import SimpleXMLRPCServer
class with_dispatch:
    def _dispatch(self, *args):
        print '_dispatch', args
        return args
server = SimpleXMLRPCServer.SimpleXMLRPCServer(('localhost',8888))
server.register_instance(with_dispatch( ))
server.serve_forever( )

From a Python interactive session on another terminal window of the same machine (or an IDLE interactive session on the same machine), you can now ...

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.