#547 closed enhancement (duplicate)
[patch] XMLRPC support for django
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Tools | Version: | |
Severity: | normal | Keywords: | |
Cc: | upadhyay@…, | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (4)
Change History (12)
by , 19 years ago
Attachment: | xmlrpc.patch added |
---|
comment:1 by , 19 years ago
Cc: | added |
---|---|
Summary: | XMLRPC support for django. → [patch] XMLRPC support for django |
Awesome! Just what I need here! Thanks!
by , 19 years ago
Attachment: | xmlrpc.3.patch added |
---|
SimpleXMLRPCServer is better than xmlrpclib.SimpleXMLRPCServer!
comment:2 by , 19 years ago
I was working with source of xmlrpclib-1.0.1, later saw an enhanced version of SimpleXMLRPCServer in standard distribution [only tested this patch with Python 2.4]. The latest patch is much cleaner, very little code copying, and supports "register_introspection_functions" [which reminds me I have not made the xmlrpc introspection methods from the parent "public", expect another patch shortly], and is more object oriented. Now we have two Views in contrib.xmlrpc, SimpleXMLRPCView and SafeXMLRPCView, later looks for "public" attribute to be True before calling, while former does not.
by , 19 years ago
Attachment: | xmlrpc.4.patch added |
---|
this one with public attribute set for SafeXMLRPCView instrospection methods.
comment:5 by , 19 years ago
How is it possible to raise an exception with this implementation of xmlrpc? I would like to send an error code (<fault>...) instead of a generic HTTP 500 server error code.
comment:7 by , 19 years ago
Cc: | removed |
---|
comment:8 by , 18 years ago
How is it possible to raise an exception with this implementation of xmlrpc? I would like to send an error code (<fault>...) instead of a generic HTTP 500 server error code.
Raise an instance of the xmlrpclib.Fault
class. Example here: Pingbacks: XML-RPC and Django.
Here is the patch.