Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save optilude/1547328 to your computer and use it in GitHub Desktop.
Save optilude/1547328 to your computer and use it in GitHub Desktop.
Index: src/infrae/wsgi/publisher.py
===================================================================
--- src/infrae/wsgi/publisher.py (revision 49248)
+++ src/infrae/wsgi/publisher.py (working copy)
@@ -19,6 +19,7 @@
from zope.component import queryMultiAdapter
from zope.event import notify
from zope.interface import implements
+from zope.interface import directlyProvides, directlyProvidedBy
from zope.site.hooks import getSite
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.security.management import newInteraction, endInteraction
@@ -60,7 +61,23 @@
"""
implements(IDefaultBrowserLayer)
+ def clone(self):
+ # Return a clone of the current request object
+ # that may be used to perform object traversal.
+ environ = self.environ.copy()
+ environ['REQUEST_METHOD'] = 'GET'
+ if self._auth:
+ environ['HTTP_AUTHORIZATION'] = self._auth
+ if self.response is not None:
+ response = self.response.clone()
+ else:
+ response = None
+ clone = self.__class__(None, environ, response, clean=1)
+ clone['PARENTS'] = [self['PARENTS'][-1]]
+ directlyProvides(clone, *directlyProvidedBy(self))
+ return clone
+
class WSGIResult(object):
"""Iterator to wrap Zope result, in order to commit/abort the
transaction at the end of the iterator iteration, and to close the
@@ -163,6 +180,11 @@
# fail, we can retry the request since we didn't send
# anything.
self.finish()
+
+ # End-of-request event handlers may have modified the response, so
+ # get it again
+ ignored, data = self.response.getWSGIResponse()
+
return data
def error(self, error, last_known_obj):
@@ -411,6 +433,4 @@
<p>Please retry later.</p>
</body>
</html>
-"""
-
-
+"""
\ No newline at end of file
Index: src/infrae/wsgi/response.py
===================================================================
--- src/infrae/wsgi/response.py (revision 49248)
+++ src/infrae/wsgi/response.py (working copy)
@@ -64,7 +64,7 @@
return formatted_cookies
-class WSGIResponse(object):
+class WSGIResponse:
"""A response object using a WSGI connection
This Response object knows nothing about ZServer, but tries to be
@@ -88,6 +88,9 @@
self.__started = False
self.__write = None
+ def clone(self):
+ return self.__class__(self.__environ, self.__start_response, self.debug_mode)
+
def redirect(self, location, status=302):
self.status = status
self.headers['Location'] = location
@@ -116,6 +119,9 @@
body = body.encode(self.default_charset)
self.body = body
+ def getBody(self):
+ return self.body
+
def setStatus(self, status, msg=None):
# We ignore msg and use our own.
self.status = status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment