Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#547 closed enhancement (duplicate)

[patch] XMLRPC support for django

Reported by: upadhyay@… Owned by: adrian
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: UI/UX:

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)

xmlrpc.patch (5.6 KB) - added by upadhyay@… 9 years ago.
Here is the patch.
xmlrpc.2.patch (6.0 KB) - added by upadhyay@… 9 years ago.
Oops, attached older patch, use this one.
xmlrpc.3.patch (2.7 KB) - added by upadhyay@… 9 years ago.
SimpleXMLRPCServer is better than xmlrpclib.SimpleXMLRPCServer!
xmlrpc.4.patch (3.0 KB) - added by upadhyay@… 9 years ago.
this one with public attribute set for SafeXMLRPCView instrospection methods.

Download all attachments as: .zip

Change History (12)

Changed 9 years ago by upadhyay@…

Here is the patch.

Changed 9 years ago by upadhyay@…

Oops, attached older patch, use this one.

comment:1 Changed 9 years ago by Boffbowsh

  • Cc paul.bowsher@… added
  • Summary changed from XMLRPC support for django. to [patch] XMLRPC support for django

Awesome! Just what I need here! Thanks!

Changed 9 years ago by upadhyay@…

SimpleXMLRPCServer is better than xmlrpclib.SimpleXMLRPCServer!

comment:2 Changed 9 years ago by upadhyay@…

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.

Changed 9 years ago by upadhyay@…

this one with public attribute set for SafeXMLRPCView instrospection methods.

comment:3 Changed 9 years ago by adrian

  • milestone Version 1.0 deleted

This isn't necessary for 1.0.

comment:4 Changed 9 years ago by jacob

  • Resolution set to duplicate
  • Status changed from new to closed

This is a subset of #115.

comment:5 Changed 9 years ago by lorenzo.viscanti@…

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:6 Changed 9 years ago by Seer

Hi all
im fine, gl all!

comment:7 Changed 9 years ago by anonymous

  • Cc paul.bowsher@… removed

comment:8 Changed 8 years ago by blinks@…

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.

Note: See TracTickets for help on using tickets.
Back to Top