diff options
author | ianb <devnull@localhost> | 2005-08-22 21:35:39 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2005-08-22 21:35:39 +0000 |
commit | 181bdc5a64903c342fea744e7f6717b6b09811d7 (patch) | |
tree | 577d536c978582cc914a3030475040f55c8436cd /paste/cgitb_catcher.py | |
parent | 9aab8336ba20636672d902dd33dbed62793eba2f (diff) | |
download | paste-181bdc5a64903c342fea744e7f6717b6b09811d7.tar.gz |
Cleanup from the last delete
Diffstat (limited to 'paste/cgitb_catcher.py')
-rw-r--r-- | paste/cgitb_catcher.py | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/paste/cgitb_catcher.py b/paste/cgitb_catcher.py index b417583..a245299 100644 --- a/paste/cgitb_catcher.py +++ b/paste/cgitb_catcher.py @@ -9,48 +9,58 @@ documentation for more: import cgitb from cStringIO import StringIO import sys +from paste.deploy import converters -class DummyFile(object): +class NoDefault: pass -def middleware(application, **kw): +class CgitbMiddleware(object): - def start_application(environ, start_response): - started = [] + def __init__(self, app, + global_conf, + display=NoDefault, + logdir=None, + context=5, + format="html"): + self.app = application + if display is NoDefault: + display = global_conf.get('debug') + self.display = converters.asbool(display) + self.logdir = logdir + self.context = int(context) + self.format = format - def detect_start_response(status, headers, exc_info=None): - started.append(start_response(status, headers, exc_info)) - return started[0] - + def __call__(self, environ, start_response): try: - app_iter = application(environ, detect_start_response) + app_iter = self.app(environ, start_response) return catching_iter(app_iter) except: - if not started: - write = start_response('500 Internal Server Error', - [('content-type', 'text/html')]) - else: - write = started[0] - dummy_file = DummyFile() - dummy_file.write = write + exc_info = sys.exc_info() + start_response('500 Internal Server Error', + [('content-type', 'text/html')], + exc_info) dummy_file = StringIO() - hook = cgitb.Hook(**kw) - hook.file = dummy_file - hook(*sys.exc_info()) + hook = cgitb.Hook(file=dummy_file, + display=self.display, + logdir=self.logdir, + context=self.context, + format=self.format) + hook(*exc_info) return [dummy_file.getvalue()] - def catching_iter(app_iter): + def catching_iter(self, app_iter): if not app_iter: raise StopIteration try: for v in app_iter: yield v except: - exc = sys.exc_info() + exc_info = sys.exc_info() dummy_file = StringIO() - hook = cgitb.Hook(**kw) - hook.file = dummy_file - hook(*exc) + hook = cgitb.Hook(file=dummy_file, + display=self.display, + logdir=self.logdir, + context=self.context, + format=self.format) + hook(*exc_info) yield dummy_file.getvalue() - - return start_application |