summaryrefslogtreecommitdiff
path: root/paste/wsgilib.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2006-07-14 16:43:27 +0000
committerianb <devnull@localhost>2006-07-14 16:43:27 +0000
commit4faed50946111b3f687cba89d5a4ad5d6a11a95e (patch)
tree63f768fd5779745cfc10d12ca2013069ec3d2093 /paste/wsgilib.py
parent9acb7d24a7aad19a01c3f03cfb9ea9716b322bdb (diff)
downloadpaste-4faed50946111b3f687cba89d5a4ad5d6a11a95e.tar.gz
Added a middleware to clear out error bodies, making them more accessible to Apache; added an app_iter wrapper for chaining app_iters from multiple sources (needed for peeking at status)
Diffstat (limited to 'paste/wsgilib.py')
-rw-r--r--paste/wsgilib.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/paste/wsgilib.py b/paste/wsgilib.py
index 85c646a..59f63ab 100644
--- a/paste/wsgilib.py
+++ b/paste/wsgilib.py
@@ -27,7 +27,8 @@ __all__ = ['get_cookies', 'add_close', 'raw_interactive',
'interactive', 'construct_url', 'error_body_response',
'error_response', 'send_file', 'has_header', 'header_value',
'path_info_split', 'path_info_pop', 'capture_output',
- 'catch_errors', 'dump_environ', 'intercept_output']
+ 'catch_errors', 'dump_environ', 'intercept_output',
+ 'chained_app_iters']
class add_close:
@@ -101,6 +102,51 @@ class add_start_close:
"WSGI request. finalization function %s not called"
% self.close_func)
+class chained_app_iters:
+
+ """
+ Chains several app_iters together, also delegating .close() to each
+ of them.
+ """
+
+ def __init__(self, *chained):
+ self.app_iters = chained
+ self.chained = [iter(item) for item in chained]
+ self._closed = False
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if len(self.chained) == 1:
+ return self.chained[0].next()
+ else:
+ try:
+ return self.chained[0].next()
+ except StopIteration:
+ self.chained.pop(0)
+ return self.next()
+
+ def close(self):
+ self._closed = True
+ got_exc = None
+ for app_iter in self.app_iters:
+ try:
+ if hasattr(app_iter, 'close'):
+ app_iter.close()
+ except:
+ got_exc = sys.exc_info()
+ if got_exc:
+ raise got_exc[0], got_exc[1], got_exc[2]
+
+ def __del__(self):
+ if not self._closed:
+ # We can't raise an error or anything at this stage
+ print >> sys.stderr, (
+ "Error: app_iter.close() was not called when finishing "
+ "WSGI request. finalization function %s not called"
+ % self.close_func)
+
def catch_errors(application, environ, start_response, error_callback,
ok_callback=None):
"""