Are the built-in HTTP servers production quality?
Christopher T King
squirrel at WPI.EDU
Mon Jul 19 21:37:02 CEST 2004
On Mon, 19 Jul 2004, Irmen de Jong wrote:
> Grant Edwards wrote:
> > Why do you have to buffer the entire file? You couldm ake two
> > almost-identical conversion passes through the file: the first
> > time, just count the "output" bytes. Finish sending the HTTP
> > headers out, then make the second pass actually writing the
> > output bytes.
> That would slow things down quite a bit, because you now
> have to do the same CPU-intensive task twice.
> But it saves memory.
> Oh, the choices...
from StringIO import StringIO
from gzip import GzipFile
gzipdata = StringIO()
gzipfile = GzipFile(mode='w', fileobj=gzipdata)
length = 0
for line in slurp_data():
line = mangle(line)
length += length(line)
for line in GzipFile(fileobj=gzipdata):
More information about the Python-list