- 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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
I don't see xmlrpc.html , the template that displays the documentation.
#
Nevermind, this should work:
#
Please login first before commenting.