This is a XML-RPC server, that uses arguments in URLs and every dispatcher instance is prepared in memory during webserver run. It's good, for example, for securing XML-RPC server with hashed strings and there are a lot of similar use cases.
Usage:
from xmlrpclib import ServerProxy
server = ServerProxy('http://example.com/xmlr-rpc/%s/' % something, allow_none=True)
server.do_something(*args)
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 26 27 28 29 30 | # urls.py:
urlpatterns = patterns('',
url(r'^xml-rpc/(?P<something>.*)/$', 'views.xmlrpc'),
)
# views.py
from SimpleXMLRPCServer import SimpleXMLRPCDispatcher
from django.views.decorators.http import require_POST
from django.http import HttpResponse
class XMLRPC(object):
def __init__(self, something):
self.something = something
def do_something(self, *args):
# code of exported function here
pass
dispatchers = {}
@require_POST
def xmlrpc(request, something):
try:
dispatcher = dispatchers[something]
except KeyError:
dispatcher = SimpleXMLRPCDispatcher(encoding=u'UTF-8', allow_none=True)
dispatcher.register_instance(XMLRPC(something))
dispatchers[something] = dispatcher
return HttpResponse(dispatcher._marshaled_dispatch(request.raw_post_data))
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.