diff options
| author | ianb <devnull@localhost> | 2005-05-22 06:24:51 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-05-22 06:24:51 +0000 |
| commit | 4426ea904aa4c6788d939814b0270d61a92ab67a (patch) | |
| tree | 29b5f9ccfdad8a28a0b52c8f2ac3c0832b9abfa6 /paste/errormiddleware.py | |
| parent | 207847cee737a9a7e227f8e10f8a8477b191f383 (diff) | |
| download | paste-4426ea904aa4c6788d939814b0270d61a92ab67a.tar.gz | |
Added documentation
Diffstat (limited to 'paste/errormiddleware.py')
| -rw-r--r-- | paste/errormiddleware.py | 91 |
1 files changed, 56 insertions, 35 deletions
diff --git a/paste/errormiddleware.py b/paste/errormiddleware.py index f077073..aa238be 100644 --- a/paste/errormiddleware.py +++ b/paste/errormiddleware.py @@ -1,41 +1,6 @@ """ Error handler middleware, and paste.config reporter integration - -Usage:: - - error_caching_wsgi_app = ErrorMiddleware(wsgi_app) - -These configuration keys are used: - -``debug``: - show the errors in the browser -``error_email``: - if present, send errors to this email address -``error_log``: - if present, write errors to this file -``show_exceptions_in_error_log``: - if true (the default) then write errors to wsgi.errors - -You can also use this outside of a web context, like:: - - import sys - import paste - import paste.error_middleware - try: - do stuff - except: - paste.error_middleware.exception_handler( - sys.exc_info(), paste.CONFIG, sys.stderr, html=False) - -If you want to report, but not fully catch the exception, call -``raise`` after ``exception_handler``, which (when given no argument) -will reraise the exception. - -By setting 'paste.throw_errors' to a true value, this middleware is -disabled. This can be useful in a testing environment where you don't -want errors to be caught and transformed. """ - import sys import traceback import cgi @@ -45,9 +10,48 @@ except ImportError: from StringIO import StringIO from paste.exceptions import formatter, collector, reporter from paste import wsgilib +from paste.docsupport import metadata + +__all__ = ['ErrorMiddleware', 'handle_exception'] class ErrorMiddleware(object): + """ + Usage:: + + error_caching_wsgi_app = ErrorMiddleware(wsgi_app) + + These configuration keys are used: + + ``debug``: + show the errors in the browser + ``error_email``: + if present, send errors to this email address + ``error_log``: + if present, write errors to this file + ``show_exceptions_in_error_log``: + if true (the default) then write errors to wsgi.errors + + By setting 'paste.throw_errors' to a true value, this middleware is + disabled. This can be useful in a testing environment where you don't + want errors to be caught and transformed. + """ + + _config_debug = metadata.Config( + """If true, show errors in the browser""", default=False) + _config_error_email = metadata.Config( + """ + The email address to send errors to (defining this enables + the emailing of errors)""", default=None) + _config_error_log = metadata.Config( + """ + A filename to write errors to. + """, default=None) + _config_show_exceptions_in_error_log = metadata.Config( + """ + If true, then write errors to ``wsgi.errors``. + """, default=True) + def __init__(self, application): self.application = application @@ -147,6 +151,23 @@ class Supplement(object): } def handle_exception(exc_info, conf, error_stream, html=True): + """ + You can also use exception handling outside of a web context, + like:: + + import sys + import paste + import paste.error_middleware + try: + do stuff + except: + paste.error_middleware.exception_handler( + sys.exc_info(), paste.CONFIG, sys.stderr, html=False) + + If you want to report, but not fully catch the exception, call + ``raise`` after ``exception_handler``, which (when given no argument) + will reraise the exception. + """ reported = False exc_data = collector.collect_exception(*exc_info) extra_data = '' |
