Is there a replacement for the plone.postpublicationhook in Plone 5.2/Zope 4?
Scenario: I generated a ZIP file within a browser view which is delivered back to the client as response.
The generated temporary ZIP file should be deleted after delivery. The ZIP file is returned through a filestream_iterator. One option might be to create a custom iterator and hook the deletion into its __del__() implementation but this appears too ugly to me. Are there any other post publication hooks available in Zope 4?
There are the ZPublisher.interfaces.IPubEnd events.
For request related cleanup, BaseRequest._hold is often used. You could for example represent your zip file as a TemporaryFile and hold it via _hold until the request object is deleted.
According to the Python docs if you use tempfile.TemporaryFile then the file is "destroyed as soon as it is closed (including an implicit close when the object is garbage collected)".