Commits

Laurence Rowe committed f5d4cae Draft

Support cloning of WSGIResponse.

Comments (0)

Files changed (2)

src/infrae/wsgi/publisher.py

 from zope.component import queryMultiAdapter, getMultiAdapter
 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 IBrowserPage, IBrowserPublisher
 from zope.security.management import newInteraction, endInteraction
     def get_plugin(self, iface):
         return self.__plugins.get(iface.__identifier__)
 
+    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

src/infrae/wsgi/response.py

         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