Django

Code

Ticket #547 (closed: duplicate)

Opened 3 years ago

Last modified 2 years ago

[patch] XMLRPC support for django

Reported by: upadhyay@gmail.com Assigned to: adrian
Milestone: Component: Tools
Version: Keywords:
Cc: upadhyay@gmail.com, Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

xmlrpc.patch (5.6 kB) - added by upadhyay@gmail.com on 09/23/05 07:01:43.
Here is the patch.
xmlrpc.2.patch (6.0 kB) - added by upadhyay@gmail.com on 09/23/05 07:06:30.
Oops, attached older patch, use this one.
xmlrpc.3.patch (2.7 kB) - added by upadhyay@gmail.com on 09/23/05 09:13:29.
SimpleXMLRPCServer is better than xmlrpclib.SimpleXMLRPCServer!
xmlrpc.4.patch (3.0 kB) - added by upadhyay@gmail.com on 09/23/05 09:50:49.
this one with public attribute set for SafeXMLRPCView instrospection methods.

Change History

09/23/05 07:01:43 changed by upadhyay@gmail.com

  • attachment xmlrpc.patch added.

Here is the patch.

09/23/05 07:06:30 changed by upadhyay@gmail.com

  • attachment xmlrpc.2.patch added.

Oops, attached older patch, use this one.

09/23/05 08:19:37 changed by Boffbowsh

  • cc changed from upadhyay@gmail.com to upadhyay@gmail.com; paul.bowsher@gmail.com.
  • summary changed from XMLRPC support for django. to [patch] XMLRPC support for django.

Awesome! Just what I need here! Thanks!

09/23/05 09:13:29 changed by upadhyay@gmail.com

  • attachment xmlrpc.3.patch added.

SimpleXMLRPCServer is better than xmlrpclib.SimpleXMLRPCServer!

09/23/05 09:47:14 changed by upadhyay@gmail.com

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.

09/23/05 09:50:49 changed by upadhyay@gmail.com

  • attachment xmlrpc.4.patch added.

this one with public attribute set for SafeXMLRPCView instrospection methods.

09/25/05 17:12:11 changed by adrian

  • milestone deleted.

This isn't necessary for 1.0.

09/29/05 08:13:35 changed by jacob

  • status changed from new to closed.
  • resolution set to duplicate.

This is a subset of #115.

04/02/06 04:50:51 changed by lorenzo.viscanti@gmail.com

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.

06/21/06 03:26:36 changed by Seer

Hi all im fine, gl all!

06/21/06 03:29:07 changed by anonymous

  • cc changed from upadhyay@gmail.com; paul.bowsher@gmail.com to upadhyay@gmail.com, .

02/01/07 15:06:49 changed by blinks@acm.org

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.


Add/Change #547 ([patch] XMLRPC support for django)




Change Properties
Action