summaryrefslogtreecommitdiff
path: root/paste/recursive.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2006-08-19 23:23:19 +0000
committerianb <devnull@localhost>2006-08-19 23:23:19 +0000
commite93b9697478f5ac16807a17ec20e506052e320ae (patch)
treeca714257dd2d4efc5331664b8efc87426436c6e3 /paste/recursive.py
parentc968f38a0ed2529915d11207ea5b99497176ac07 (diff)
downloadpaste-e93b9697478f5ac16807a17ec20e506052e320ae.tar.gz
Extensions to recursive for WSGIRemote
Diffstat (limited to 'paste/recursive.py')
-rw-r--r--paste/recursive.py48
1 files changed, 43 insertions, 5 deletions
diff --git a/paste/recursive.py b/paste/recursive.py
index 479eed3..50ab942 100644
--- a/paste/recursive.py
+++ b/paste/recursive.py
@@ -18,7 +18,7 @@ you to trigger recursive redirects and forwards.
``paste.recursive.old_path_info``:
A list of previous ``PATH_INFO`` values from previous redirects.
-Raise ``ForewardRequestException(new_path_info)`` to do a forward
+Raise ``ForwardRequestException(new_path_info)`` to do a forward
(aborting the current request).
"""
@@ -65,13 +65,15 @@ class RecursiveMiddleware(object):
environ['paste.recursive.forward'] = Forwarder(
self.application,
environ,
- start_response,
- )
+ start_response)
environ['paste.recursive.include'] = Includer(
self.application,
environ,
- start_response
- )
+ start_response)
+ environ['paste.recursive.include_app_iter'] = IncluderAppIter(
+ self.application,
+ environ,
+ start_response)
my_script_name = environ.get('SCRIPT_NAME', '')
current_path_info = environ.get('PATH_INFO', '')
environ['paste.recursive.script_name'] = my_script_name
@@ -336,3 +338,39 @@ class IncludedResponse(object):
return self.str
body = property(body__get)
+
+class IncluderAppIter(Recursive):
+ """
+ Like Includer, but just stores the app_iter response
+ (be sure to call close on the response!)
+ """
+
+ def activate(self, environ):
+ response = IncludedAppIterResponse()
+ def start_response(status, headers, exc_info=None):
+ if exc_info:
+ raise exc_info[0], exc_info[1], exc_info[2]
+ response.status = status
+ response.headers = headers
+ return response.write
+ app_iter = self.application(environ, start_response)
+ response.app_iter = app_iter
+ return response
+
+class IncludedAppIterResponse(object):
+
+ def __init__(self):
+ self.status = None
+ self.headers = None
+ self.accumulated = []
+ self.app_iter = None
+ self._closed = False
+
+ def close(self):
+ assert not self._closed, (
+ "Tried to close twice")
+ if hasattr(self.app_iter, 'close'):
+ self.app_iter.close()
+
+ def write(self, s):
+ self.accumulated.append