[mod_python] onunload ie mod_python

Nick nick at dd.revealed.net
Thu Oct 27 11:40:39 EDT 2005


Graham Dumpleton wrote:
> 
> On 27/10/2005, at 6:31 AM, Nick wrote:
> 
>> See also  
>> http://developer.apple.com/internet/webcontent/xmlhttpreq.html for  
>> another solution (there are many resources for this information, but 
>> I  like that one best).
>>
>> SimpleXMLRPCServer is a standard module in Python, and I don't think  
>> it's as complex as you might think, but the above solution might 
>> yield  quicker results for you.
> 
> 
> As far as integrating XML-RPC into mod_python, you are possibly better
> of using the xmlrpclib.dumps() and xmlrpclib.loads() functions directly.
>  From memory this gives better control over handling errors. At least
> I know I had a good reason at the time which I can't think of right now.
> Possibly because overriding SimpleXmlRpcServer didn't provide a good
> way of returning a 404 when function didn't exist.

I don't believe you must return a 404 when a function doesn't exist, but 
only when a service doesn't exist.  From the spec:

"Unless there's a lower-level error, always return 200 OK."

A non-existant function would return a fault code.  A simple xmlrpc handler 
for mod_python would look like:

from mod_python import apache
import SimpleXMLRPCServer

dispatcher = SimpleXMLRPCServer.SimpleXMLRPCDispatcher()

# just add any function to the dispatcher with:
# dispatcher.register_function(my_func)

# for convenience:
dispatcher.register_introspection_functions()

def handler(req):
     try:
         req.write(dispatcher._marshaled_dispatch(req.read())
         return apache.OK
     except:
         return apache.HTTP_INTERNAL_SERVER_ERROR

And that's it.  Obviously this can be made more robust, but it usually 
doesn't need to be.  The dispatcher should catch all exceptions and send a 
fault code.

Nick


More information about the Mod_python mailing list