[patch] XMLRPC support for django
|Reported by:||Owned by:||Adrian Holovaty|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I have a working XMLRPC implementation for django. Here is how to use it:
Add the following to urlpatterns:
urlpatterns = patterns('', (r'^xmlrpc/', 'myproject.apps.xrpc.views.xrpc.serve'), )
I have borrowed code heavily from SimpleXMLRPCServer, which comes with standard python distribution, so we have the same API as described in its documentation, other than the constructor. I have added some security enhancement, so every published method must contain a public attribute which must be set to True before we would serve it.
Here is an example xrpc.py:
from django.contrib.xmlrpc import SimpleXMLRPCView class c: def f(self): return "public func, will be served." f.public = True def g(self): return "private, wont be served." serve = SimpleXMLRPCView() serve.register_instance(c())
Finally an example of how to use it:
>>> import xmlrpclib >>> server = xmlrpclib.Server('http://localhost:8000/xrpc/') >>> server.f() 'public func, will be served.' >>> server.g() Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\Python24\lib\xmlrpclib.py", line 1096, in __call__ return self.__send(self.__name, args) File "C:\Python24\lib\xmlrpclib.py", line 1383, in __request verbose=self.__verbose File "C:\Python24\lib\xmlrpclib.py", line 1137, in request headers ProtocolError: <ProtocolError for localhost:8000/xrpc/: 500 INTERNAL SERVER ERROR> >>>
Will attach the patch shortly.
Change History (12)
comment:1 Changed 12 years ago by
|Summary:||XMLRPC support for django. → [patch] XMLRPC support for django|