[Zope3-dev] PEP 333 and Zope
Phillip J. Eby
pje at telecommunity.com
Tue Nov 9 14:45:44 EST 2004
At 05:38 PM 11/9/04 +0100, Eckart Hertzler wrote:
>On Tuesday 09 November 2004 17:04, Phillip J. Eby wrote:
> > The second issue is that your implementation won't work properly for
> > streaming output or large files, because you're buffering all the data in
> > memory, duplicating the buffering that already exists in a publisher
> > response. Instead of a StringIO, you need to create a simple file-like
> > object that wraps the WSGI 'write()' functionality. The only case in
> which
> > PublisherApp.__iter__ should yield a value is if the response wasn't
> > actually sent to the output stream.
> >
> >
>This was due to my limited understanding of the publisher internals.
>It seemed to me, that the publisher produced the body in one block, so
>I did not see how streaming might happen...
It's in the 'write()' method of the response. The simplest way to make
this work, I think, would be to pass the WsgiHeaderOutput object as the
outstream, and add a 'write()' method to it that calls the WSGI 'write'
callable. Finally, the application object should call 'publish()' in
'__init__', rather than in '__iter__'. You could in fact probably drop the
iteration altogether at that point.
On a side note, I've just noticed that there appears to be a bug in the
trunk version of zope.publisher.http.HTTPResponse class; it looks like the
'output()' method will incorrectly set the Content-Length header to the
size of the first block of streamed data, overriding any manually-set
content length, and causing variable-length streams to have an incorrect,
fixed-length header. Somebody should probably add a test for that.
More information about the Zope3-dev
mailing list