I just started using Webware and it is such a breath of fresh air=
in the Python Web development realm. Excellent job!
I'm trying to create a servlet which can return a Python string=
to the user's browser as a zip file download. Information is=
sent from the user via a post request which is then processed by=
the servlet to produce a final string. I could write that=
string to disk, zip the file, and redirect the user to the file.=
But a Java guru friend of mine showed me a trick where he used=
java.util.zip (something like that) to do it all in memory=
without writing to disk. This functionality is part of the=
built-in Java library he used. This way things are fast and=
there's no need to write a special clean up program to try and=
guess when the user had downloaded the file.
This trick should be just as possible in Python but I haven't=
figured it out yet. I know I can compress strings with zlib but=
I'm not sure how to create a response to make it look like a zip=
file to the user's browser.
Here's the meager first attempt I made without compressing the=
string just to see if the browser would behave as if it were=
seeing a zip file. I just added what I thought would be the=
appropriate mime type in the header:
from WebKit.Servlet import Servlet
def respond(self, trans):
This servlet just returns the entire response string as a string.=
From: Ian Bicking <ianb@co...> - 2002-08-19 17:24:48
On Mon, 2002-08-19 at 12:14, jlawhead@... wrote:
> from WebKit.Servlet import Servlet
> class ZipSample(Servlet):
> def respond(self, trans):
> trans.response().write('Content-type: application/zip; name="test.zip"\nContent-Transfer-Encoding: base64\n\n\nHello, world!\n')
You need use addHeader, like:
trans.response().addHeader('Content-type', 'application/zip; name="test.zip")
There's no particular reason to use base64, but each header would be its
own addHeader() call.
Get latest updates about Open Source Projects, Conferences and News.