Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#547 closed enhancement (duplicate)

[patch] XMLRPC support for django

Reported by: upadhyay@… 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)

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

Download all attachments as: .zip

Change History (12)

by upadhyay@…, 19 years ago

Attachment: xmlrpc.patch added

Here is the patch.

by upadhyay@…, 19 years ago

Attachment: xmlrpc.2.patch added

Oops, attached older patch, use this one.

comment:1 by Boffbowsh, 19 years ago

Cc: paul.bowsher@… added
Summary: XMLRPC support for django.[patch] XMLRPC support for django

Awesome! Just what I need here! Thanks!

by upadhyay@…, 19 years ago

Attachment: xmlrpc.3.patch added

SimpleXMLRPCServer is better than xmlrpclib.SimpleXMLRPCServer!

comment:2 by upadhyay@…, 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 upadhyay@…, 19 years ago

Attachment: xmlrpc.4.patch added

this one with public attribute set for SafeXMLRPCView instrospection methods.

comment:3 by Adrian Holovaty, 19 years ago

milestone: Version 1.0

This isn't necessary for 1.0.

comment:4 by Jacob, 19 years ago

Resolution: duplicate
Status: newclosed

This is a subset of #115.

comment:5 by lorenzo.viscanti@…, 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:6 by Seer, 19 years ago

Hi all
im fine, gl all!

comment:7 by anonymous, 19 years ago

Cc: paul.bowsher@… removed

comment:8 by blinks@…, 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.

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