Login

In-memory XML-RPC server based on URL

Author:
diverman
Posted:
June 23, 2010
Language:
Python
Version:
1.2
Score:
0 (after 0 ratings)

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

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 9 months, 4 weeks ago
  5. Help text hyperlinks by sa2812 10 months, 3 weeks ago

Comments

Please login first before commenting.