Subsections


3.3.3 XMLRPC Responders

The XMLRPC responder implements an application website. XMLRPC is a language-neutral protocol for distributed computing, using XML for serialization and HTTP for transport. The Python standard library includes a well-written XMLRPC library, which forms the basis for this class. By mixing the XMLRPC responder into your class, you can easily make your instance's methods available to clients over the network. Instances inherit one attribute and two methods:

protected
A tuple of names of methods on self which should never be served via XMLRPC. This class attribute on XMLRPC is set to the empty tuple.

respond( request)
This is a pass-through for serve_xmlrpc. It can safely be overriden, but in most cases need not be.

serve_xmlrpc( request)
Proxies methods on self via XMLRPC. request is a Request object. Assuming request is an XMLRPC request for method name, the following conditions trigger an XMLRPC <fault> response with <faultCode> 404:

  1. name starts with an underscore.

  2. name is respond or serve_xmlrpc.

  3. name is named in protected.

  4. The instance does not have a method named name.

3.3.3.1 An Example

In a Python shell, create an XMLRPC server like so:

>>> import httpy
>>> class Responder(httpy.responders.XMLRPC):
...   protected = ['private']
...   def private(self):
...     return 'leave me alone!'
...   def ping(self):
...     return 'pong'
...
>>> responder = Responder()
>>> coupler = httpy.couplers.StandAlone(responder)
>>> coupler.go()
httpy.server     INFO     httpy started on port 8080

Then, in a second shell, you can talk to your server like this:

>>> import xmlrpclib
>>> server = xmlrpclib.ServerProxy('http://localhost:8080/')
>>> server.ping()
'pong'
>>> server.private()
Traceback (most recent call last):
...
xmlrpclib.Fault: <Fault 404: "method 'private' not found">
>>>
httpy is Zeta software. It is copyright © 2006 by Chad Whitacre, and is offered free of charge, warranty, and restrictions.