diff options
| -rw-r--r-- | paste/cgitb_catcher.py | 37 | ||||
| -rw-r--r-- | setup.py | 2 |
2 files changed, 35 insertions, 4 deletions
diff --git a/paste/cgitb_catcher.py b/paste/cgitb_catcher.py index 9492498..09d7b49 100644 --- a/paste/cgitb_catcher.py +++ b/paste/cgitb_catcher.py @@ -21,14 +21,14 @@ class NoDefault: class CgitbMiddleware(object): def __init__(self, app, - global_conf, + global_conf=None, display=NoDefault, logdir=None, context=5, format="html"): - # @@: global_conf should only be present in a seperate - # function for the entry point self.app = app + if global_conf is None: + global_conf = {} if display is NoDefault: display = global_conf.get('debug') if isinstance(display, basestring): @@ -83,3 +83,34 @@ class CgitbMiddleware(object): hook(*exc_info) return dummy_file.getvalue() +def make_cgitb_middleware(self, app, global_conf, + display=NoDefault, + logdir=None, + context=5, + format='html'): + """ + Wraps the application in the ``cgitb`` (standard library) + error catcher. + + display: + If true (or debug is set in the global configuration) + then the traceback will be displayed in the browser + + logdir: + Writes logs of all errors in that directory + + context: + Number of lines of context to show around each line of + source code + """ + from paste.deploy.converters import asbool + if display is not NoDefault: + display = asbool(display) + if 'debug' in global_conf: + global_conf['debug'] = asbool(global_conf['debug']) + return CgitbMiddleware( + app, global_conf=global_conf, + display=display, + logdir=logdir, + context=context, + format=format) @@ -154,7 +154,7 @@ For the latest changes see the `news file [paste.filter_app_factory] error_catcher = paste.exceptions.errormiddleware:make_error_middleware - cgitb = paste.cgitb_catcher:CgitbMiddleware + cgitb = paste.cgitb_catcher:make_cgitb_middleware flup_session = paste.flup_session:SessionMiddleware [Flup] gzip = paste.gzipper:middleware httpexceptions = paste.httpexceptions:make_middleware |
