Documentation for repoze.bfg.xmlrpc

XML-RPC support for the repoze.bfg web framework.

repoze.bfg.xmlrpc Installation

repoze.bfg.xmlrpc is a package that ships outside the main repoze.bfg distribution. To install the package, use easy_install:

easy_install -i http://dist.repoze.org/bfgsite/simple repoze.bfg.xmlrpc

Or obtain the packge via http://svn.repoze.org/repoze.bfg.xmlrpc and use setup.py install.

repoze.bfg.xmlrpc Usage

Create a function in the form below. The function will be meant to be called with positional parameters from an XML-RPC request.

1
2
def say_hello(context, name):
    return 'Hello, %s' % name

Then add the @xmlrpc_view decorator to the function.

1
2
3
4
5
from repoze.bfg.xmlrpc import xmlrpc_view

@xmlrpc_view
def say_hello(context, name):
    return 'Hello, %s' % name

Then configure your application registry to point to the say_hello view.

1
2
3
4
5
<bfg:view
  name="say_hello"
  view=".views.say_hello"
  for="*"
  />

Then call the function via an XML-RPC client. Note that any XML-RPC methodName will be ignored; you must point the client directly at the view URL; traversal doesn’t work from there.

1
2
3
4
>>> from xmlrpclib import ServerProxy
>>> s = ServerProxy('http://localhost:6543/say_hello')
>>> s('Chris')
Hello, Chris

API Documentation for repoze.bfg.xmlrpc

repoze.bfg.xmlrpc.xmlrpc_view(wrapped)

Function meant to be used as a decorator. The xmlrpc_view function turns functions which accept params and return Python structures into functions suitable for use as bfg views which an XML-RPC response. The decorated function must accept a context argument and zero or more positional arguments (conventionally named *params).

E.g.:

from repoze.bfg.xmlrpc import xmlrpc_view

@xmlrpc_view
def say(context, what):
    if what == 'hello'
        return {'say':'Hello!'}
    else:
        return {'say':'Goodbye!'}

Equates to:

from repoze.bfg.xmlrpc import parse_xmlrpc_request
from repoze.bfg.xmlrpc import xmlrpc_response

def say_view(context, request):
    params, method = parse_xmlrpc_request(request)
    return say(context, *params)

def say(context, what):
    if what == 'hello'
        return {'say':'Hello!'}
    else:
        return {'say':'Goodbye!'}

Note that if you use repoze.bfg.convention, you must decorate your view function in the following order for it to be recognized by the convention machinery as a view:

@bfg_view(name='say')
@xmlrpc_view
def say(context, what):
    if what == 'hello'
        return {'say':'Hello!'}
    else:
        return {'say':'Goodbye!'}

In other words do not decorate it in xmlrpc_view, then bfg_view order; it won’t work.

repoze.bfg.xmlrpc.xmlrpc_marshal(data)
Marshal a Python data structure into an XML document suitable for use as an XML-RPC response and return the document. If data is an xmlrpclib.Fault instance, it will be marshalled into a suitable XML-RPC fault response.
repoze.bfg.xmlrpc.xmlrpc_response(data)
Marshal a Python data structure into a webob Response object with a body that is an XML document suitable for use as an XML-RPC response with a content-type of text/xml and return the response.
repoze.bfg.xmlrpc.parse_xmlrpc_request(request)
Deserialize the body of a request from an XML-RPC request document into a set of params and return a two-tuple. The first element in the tuple is the method params as a sequence, the second element in the tuple is the method name.

Indices and tables