pylons.controllers.xmlrpc – XMLRPCController Class

The base WSGI XMLRPCController

Module Contents

class pylons.controllers.xmlrpc.XMLRPCController

XML-RPC Controller that speaks WSGI

This controller handles XML-RPC responses and complies with the XML-RPC Specification as well as the XML-RPC Introspection specification.

By default, methods with names containing a dot are translated to use an underscore. For example, the system.methodHelp is handled by the method system_methodHelp().

Methods in the XML-RPC controller will be called with the method given in the XMLRPC body. Methods may be annotated with a signature attribute to declare the valid arguments and return types.

For example:

class MyXML(XMLRPCController):
    def userstatus(self):
        return 'basic string'
    userstatus.signature = [ ['string'] ]

    def userinfo(self, username, age=None):
        user = LookUpUser(username)
        response = {'username':user.name}
        if age and age > 10:
            response['age'] = age
        return response
    userinfo.signature = [['struct', 'string'],
                          ['struct', 'string', 'int']]

Since XML-RPC methods can take different sets of data, each set of valid arguments is its own list. The first value in the list is the type of the return argument. The rest of the arguments are the types of the data that must be passed in.

In the last method in the example above, since the method can optionally take an integer value both sets of valid parameter lists should be provided.

Valid types that can be checked in the signature and their corresponding Python types:

'string' - str
'array' - list
'boolean' - bool
'int' - int
'double' - float
'struct' - dict
'dateTime.iso8601' - xmlrpclib.DateTime
'base64' - xmlrpclib.Binary

The class variable allow_none is passed to xmlrpclib.dumps; enabling it allows translating None to XML (an extension to the XML-RPC specification)

Note

Requiring a signature is optional.

__call__(environ, start_response)

Parse an XMLRPC body for the method, and call it with the appropriate arguments

system_listMethods()

Returns a list of XML-RPC methods for this XML-RPC resource

system_methodHelp(name)

Returns the documentation for a method

system_methodSignature(name)

Returns an array of array’s for the valid signatures for a method.

The first value of each array is the return value of the method. The result is an array to indicate multiple signatures a method may be capable of.