[Zope3-Users] Re: substitute for deprecated response.write()?

Philipp von Weitershausen philipp at weitershausen.de
Fri Dec 30 04:15:50 EST 2005


first, thanks for bringing this to my attention! I wasn't aware at all
that one of my examples was using response.write(). It wouldn't have
changed anything, I think, as I think response.write() was bound to go
anyways, but at least I should have reacted in some sort of way. Sorry
about that.

> I am red faced (and blurry-eyed, its 1am here)- I found the answer in
> the archives, in September:
> On Fri, Sep 16, 2005 at 11:50:19AM -0400, Stephan Richter wrote:
>>> Just return the data; it is handled properly now

Yes and no. Sure you can just return the data which has about the same
effect as response.write() had: it's not very memory efficient. If the
produced PDF file gets large, it holds up a lot of memory until the
request is over. A better way is to return a temporary file which holds
the data and from which the data is then streamed to the client.

Here's what I've added to my errata page:

  page 204, Example 12.24, line 17: Using the ``write()`` method of
  HTTP-based responses does not provide a performance advantage in
  Zope X3 3.0 and 3.1 and is not supported anymore in Zope 3.2 and
  higher.  To effectively return large data without holding it in
  memory, it is now recommended to create a temporary file and return

    import tempfile
    f = tempfile.TemporaryFile()
    return f

  This will only work with Zope 3.2 and higher.

Hope that helps.


More information about the Zope3-users mailing list