Are the built-in HTTP servers production quality?

Christopher T King squirrel at WPI.EDU
Mon Jul 19 15:37:02 EDT 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...

Choices, indeed:

 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)
     gzipfile.write(line)

 gzipfile.close()

 gzipdata.seek(0)
 print length
 for line in GzipFile(fileobj=gzipdata):
     spew_data(line)

;)





More information about the Python-list mailing list