Login

An XML-RPC Decorator

Author:
blinks
Posted:
March 19, 2007
Language:
Python
Version:
Pre .96
Tags:
xml-rpc
Score:
13 (after 13 ratings)

Drop this package wherever you want, import the decorator, and use it with one argument to decorate any function you want (@xmlrpc('pingback.ping')). That function is now available on your XML-RPC interface, available through this view.

Make sure to provide the view (call_xmlrpc) with a URL so that it's accessible.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from SimpleXMLRPCServer import SimpleXMLRPCDispatcher
dispatcher = SimpleXMLRPCDispatcher()
                                                                                
def call_xmlrpc(request):
    """Dispatch XML-RPC requests."""
    if request.method == 'POST':
        # Process XML-RPC call
        response = HttpResponse(mimetype='text/xml')
        response.write(dispatcher._marshaled_dispatch(request.raw_post_data))
        response['Content-length'] = str(len(response.content))
        return response
    else:
        # Show documentation on available methods
        response = HttpResponse()
        t = loader.get_template('xmlrpc.html')
        c = Context({'methods': dispatcher.system_listMethods()})
        response.write(t.render(c))
        return response

def xmlrpc(uri):
    """A decorator for XML-RPC functions."""
    def register_xmlrpc(fn):
        dispatcher.register_function(fn, uri)
        return fn
    return register_xmlrpc

More like this

  1. Format transition middleware by limodou 8 years, 1 month ago
  2. In-memory XML-RPC server based on URL by diverman 4 years, 9 months ago
  3. JSON View Decorator by bryanpieper 4 years, 8 months ago
  4. Decorator that limits request methods by schinckel 5 years, 8 months ago
  5. xmlrpc basic auth by jackherer 7 years, 5 months ago

Comments

Tobu (on September 28, 2007):

I don't see xmlrpc.html , the template that displays the documentation.

#

Tobu (on September 28, 2007):

Nevermind, this should work:

<html>
<body>
XML-RPC Methods:
<ol>
    {% for method in methods %}
        <li>{{method.name}} &mdash; {{method.signature}}</li>
    {% endfor %}
</ol>
</body>
</html>

#

Please login first before commenting.