diff options
author | Helmut Grohne <helmut@subdivi.de> | 2007-04-14 23:35:49 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2007-04-14 23:35:49 +0200 |
commit | 293a9e81bad7fe6f53980e229eed677b4101b846 (patch) | |
tree | da5638e0c72960f53cdd9cbe9f3f446edfa74eea /wsgitools/middlewares.py | |
parent | 2435f82361f6bc4dcd51e1305905ecbbb5757f50 (diff) | |
download | wsgitools-293a9e81bad7fe6f53980e229eed677b4101b846.tar.gz |
added TracebackMiddleware
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r-- | wsgitools/middlewares.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py index 9eab2a1..ea61aca 100644 --- a/wsgitools/middlewares.py +++ b/wsgitools/middlewares.py @@ -1,6 +1,8 @@ __all__ = [] import time +import sys +import cgitb from filters import CloseableList, CloseableIterator try: import cStringIO as StringIO @@ -265,3 +267,21 @@ class BasicAuthMiddleware: headers.append(('Content-length', len(html))) start_response(status, headers) return [html] + +__all__.append("TracebackMiddleware") +class TracebackMiddleware: + """In case the application throws an exception this middleware will show an + html-formatted traceback using cgitb.""" + def __init__(self, app): + """app is the wsgi application to proxy.""" + self.app = app + def __call__(self, environ, start_response): + """wsgi interface""" + try: + return self.app(environ, start_response) + except: + exc_info = sys.exc_info() + data = cgitb.html(exc_info) + start_response("200 OK", [("Content-type", "text/html"), + ("Content-length", str(len(data)))]) + return [data] |