Login

An XML-RPC Decorator

Author:
blinks
Posted:
March 19, 2007
Language:
Python
Version:
Pre .96
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. Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
  5. Help text hyperlinks by sa2812 1 year, 6 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.