Skip to main content

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

Testing Dependencies

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oops_wsgi-0.1.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oops_wsgi-0.1.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file oops_wsgi-0.1.0.tar.gz.

File metadata

  • Download URL: oops_wsgi-0.1.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for oops_wsgi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b0fe4c02f1d015a4973b37d39036249164295f7412217403b3db566b24d6e736
MD5 f574ded5af5617855844cb646344ef6f
BLAKE2b-256 fe84bfa89f3a1e8335202f90233298fb783b7ed0cf4ed82bf33bab659f3272d2

See more details on using hashes here.

File details

Details for the file oops_wsgi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oops_wsgi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for oops_wsgi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f51cfec5ee16165708caff4e3ef457ed183ac3190a611e9e6f64904910ca216
MD5 928d6b8b4388a1196952cd45163db6fe
BLAKE2b-256 f0031121c835136e20edf11d5987cd0847b220656a4e98bbdcfd25be94e01624

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page