Ticket #356: rpc.py

File rpc.py, 997 bytes (added by hugo <gb@…>, 19 years ago)

rpc connector source (this is the view function you need to hook into urls)

Line 
1import sys
2import time
3import xmlrpclib
4
5from django.utils.httpwrappers import HttpResponse
6from django.conf import settings
7
8from django.core.rpcdispatch import dispatcher
9
10DEBUG = 0
11if hasattr(settings, 'DEBUG_RPC'):
12 DEBUG = settings.DEBUG_RPC
13
14def call(request):
15 """
16 This is the view you need to map into your URL space to process RPC
17 calls.
18 """
19 p, u = xmlrpclib.getparser()
20 p.feed(request.raw_post_data)
21 p.close()
22 args = u.close()
23 method = u.getmethodname()
24 func = dispatcher().find(method)
25 if DEBUG: print method, func, args
26 if func is not None:
27 try:
28 result = func(*args)
29 xml = xmlrpclib.dumps((result,), methodresponse=1)
30 if DEBUG: print result
31 except Exception, e:
32 if DEBUG: print e
33 xml = xmlrpclib.dumps(xmlrpclib.Fault(-32400, 'system error: %s' % e), methodresponse=1)
34 if DEBUG: print
35 else:
36 xml = xmlrpclib.dumps(xmlrpclib.Fault(-32601, 'method unknown: %s' % method), methodresponse=1)
37 return HttpResponse(xml, mimetype='text/xml; charset=utf-8')
38
Back to Top