OOPS wsgi middleware.
Project description
Copyright (c) 2011, Canonical Ltd
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3 only.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. GNU Lesser General Public License version 3 (see the file LICENSE).
The oops_wsgi package provides integration glue between wsgi web servers and the oops error reporting system (http://pypi.python.org/pypi/oops).
Dependencies
Python 2.6+ or 3.3+
Testing Dependencies
subunit (http://pypi.python.org/pypi/python-subunit) (optional)
testtools (http://pypi.python.org/pypi/testtools)
Usage
oops_wsgi provides integration with an oops.Config, permitting errors in your web application to be gathered centrally, with tracebacks and other diagnostic information.
Typically, something like this:
Setup your configuration:
>>> from oops import Config >>> config = Config()
Note that you will probably want at least one publisher, or your reports will be discarded.
Add in wsgi specific hooks to the config:
>>> oops_wsgi.install_hooks(config)
This is a convenience function - you are welcome to pick and choose the creation or filter hooks you want from oops_wsgi.hooks.
Create your wsgi app as normal, and then wrap it:
>>> app = oops_wsgi.make_app(app, config)
If any exception bubbles up through this middleware, an oops will be logged. If the body of the request had not started, then a custom page is shown that shows the OOPS id, and the exception is swallowed. Exceptions that indicate normal situations like end-of-file on a socket do not trigger OOPSes. If the OOPS is filtered, or no publishers are configured, then the exception will propogate up the stack - the oops middleware cannot do anything useful in these cases. (For instance, if you have a custom 404 middleware above the oops middleware in the wsgi stack, and filter 404 exceptions so they do not create reports, then if the oops middleware did anything other than propogate the exception, your custom 404 middleware would not work.
If the body had started, then there is no way to communicate the OOPS id to the client and the exception will propogate up the wsgi app stack.
You can customise the error page if you supply a helper that accepts (environ, report) and returns HTML to be sent to the client.
>>> def myerror_html(environ, report): ... return '<html><body><h1>OOPS! %s</h1></body></html>' % report['id'] >>> app = oops_wsgi.make_app(app, config, error_render=myerror_html)
Or you can supply a string template to be formatted with the report.
>>> json_template='{"oopsid" : "%(id)s"}' >>> app = oops_wsgi.make_app(app, config, error_template=json_template)
For more information see pydoc oops_wsgi.
Installation
Either run setup.py in an environment with all the dependencies available, or add the working directory to your PYTHONPATH.
Development
Upstream development takes place at https://launchpad.net/python-oops-wsgi. To setup a working area for development, if the dependencies are not immediately available, you can use ./bootstrap.py to create bin/buildout, then bin/py to get a python interpreter with the dependencies available.
To run the tests use the runner of your choice, the test suite is oops_wsgi.tests.test_suite.
For instance:
$ bin/py -m testtools.run oops_wsgi.tests.test_suite
If you have testrepository you can run the tests with that:
$ testr run
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file oops_wsgi-0.0.15.tar.gz
.
File metadata
- Download URL: oops_wsgi-0.0.15.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4bd7ae45ba209f6b41accf39714cd510c498547366c19e0b0bfed02b47d5b26 |
|
MD5 | 352024d4af9d3921bed2cfb32330371f |
|
BLAKE2b-256 | 45527047442ab9f21588b7ffc100fc71304b0aba938668549d2f89d242357746 |