[mod_python] Sessions and Cookies with mod_python and more

Graham Dumpleton grahamd at dscpl.com.au
Wed Nov 17 18:57:27 EST 2004

On Nov 17 17:44, Bram <bram-lists at phoenux.org> wrote:
> Subject: Re: [mod_python] Sessions and Cookies with mod_python and more
> Graham,
> You hit the nail on the head, as I am speaking of XML-RPC. Your form 
> example is a good one, and I will take a closer look at 
> mod_python.utils.FieldStorage. Thanks for that bit of info. Although, I 
> am not sure that it will meet my needs completely. That being said I 
> will explain further. I am currently using a mod_perl XML-RPC server 
> that was modified to handle large binary files. I have found that 
> passing large binary strings in XML via XML-RPC (or any other protocol 
> for that matter) even with careful attention to the encoding can lead to 
> problems. I know that with XML-RPC one may use the <base64> tag to 
> encapsulate binary data directly within the XML document. However, is 
> this the best way to handle this when dealing with large files? In my 
> mod_perl implementation, I have a multipart/related handing situation 
> setup, i.e. the first part of the multipart/related message would be the 
> XML-RPC request/reply and the second (and 3rd, 4th, etc. if need) part 
> is binary data referenced by the XML-RPC data. I am not saying this is 
> the best solution, and may not even adhere to any specification, but I 
> haven't found a better one to date. I admit it is a little hackish. :) 
> Any suggestions to improve upon this, or even suggestions totally 
> rethinking it? In short, what would be an efficient way to transfer 
> large files via an XML based, standards based web service like XML-RPC?

Hmmm, not really XML-RPC. More like SOAP with attachments.

Since though you are still trying to use the simpler XML-RPC for
the structured data component, also have a look at SimpleXMLRPCServer
and xmlrpclib modules.

It isn't too hard to use SimpleXMLRPCServer as a base to construct a
XML-RPC handler for mod_python. See vampire/xmlrpc.py in my Vampire
package at "http://www.dscpl.com.au/projects/vampire" as an example.

In your case, you would need to change things though so as to use the
convention you want to to indicate that you are returning attachments
to the response or a multipart response.

Ie., normally xmlrpclib/SimpleXMLRPCServer will try and encode the
complete result of the method called. You might modify it such that if
you returned a class object of specific type, which had named components
in it and how to encode each, that the basic XML-RPC handler behaved
a bit different and put it back as multipart data. Obviously a standard
XML-RPC client can't be used to talk to it, but you already know that.

As well as looking at SimpleXMLRPCServer and xmlrpclib, Python also has
the cgi module. It also has a version of FieldStorage in it as well as some
more basic functions for parsing multipart messages. This would be
useful on the client side as the FieldStorage class in mod_python isn't
going to be usable outside of the context of a mod_python handler.

Having said all that, the REST folks would probably say that you shouldn't
return multipart data and that instead you should return a response
which then enumerates the links to each part and a subsequent request
made to get each bit. :-)

BTW, mean't "mod_python.util.FieldStorage". Ie., "util", not "utils".

Graham Dumpleton (grahamd at dscpl.com.au)

More information about the Mod_python mailing list