In-memory XML-RPC server based on URL

 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 5 years, 2 months ago
  2. An XML-RPC Decorator by blinks 7 years ago
  3. Format transition middleware by limodou 7 years, 1 month ago
  4. Simple views dispatcher by http methods by kmerenkov 4 years, 5 months ago
  5. Function decorator for caching function results in local memory by bikeshedder 1 year, 6 months ago

Comments

(Forgotten your password?)