Login

In-memory XML-RPC server based on URL

Author:
diverman
Posted:
June 23, 2010
Language:
Python
Version:
1.2
Tags:
xml server dispatcher xmlrpc
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. general-purpose django XMLRC dispatcher by teepark 6 years, 5 months ago
  2. An XML-RPC Decorator by blinks 8 years, 4 months ago
  3. Format transition middleware by limodou 8 years, 5 months ago
  4. Simple views dispatcher by http methods by kmerenkov 5 years, 8 months ago
  5. Function decorator for caching function results in local memory by bikeshedder 2 years, 10 months ago

Comments

Please login first before commenting.