Skip to main content

Provides middleware for detecting and correcting errors in web pages that are served via the standard WSGI protocol used by most Python web frameworks. By default, validation errors are logged to the “strainer.middleware” channel using the standard Python logging module.

You should read the documentation for your web framework to find out how to get the “WSGI application” that is responsible for serving your web site. In Pylons, for example, the following code could be added in the config/middleware.py file.

To add HTML/XHTML/XML well-formedness validation to your WSGI app:

>>> from strainer.middleware import WellformednessCheckerMiddleware
>>> app = WellformednessCheckerMiddleware(app)

This uses the expat parser to detect most syntax errors and mismatched tags, but it won’t perform stricter checks that the document structure matches the XHTML DTD, such as detecting disallowed child tags or attributes. For that you should install a recent version of lxml (e.g. “easy_install lxml”) and use XHTMLValidatorMiddleware instead, with code such as:

>>> from strainer.middleware import XHTMLValidatorMiddleware
>>> app = XHTMLValidatorMiddleware(app)

To add JSON validation to your WSGI app:

>>> from strainer.middleware import JSONValidatorMiddleware
>>> app = JSONValidatorMiddleware(app)

If your web framework doesn’t provide an alternative handler for the error messages that are logged to the “strainer.middleware” channel, you can have them printed to sys.stderr with:

>>> import logging
>>> logging.basicConfig()

To add automatic correction of common HTML and XHTML errors to your WSGI app:

>>> from strainer.middleware import XHTMLifyMiddleware
>>> app = XHTMLifyMiddleware(app)

This is somewhat experimental, but it will improve faster if people use it and email us bug reports…

As with all (or at least most) WSGI middleware, you can also combine them:

>>> app = XHTMLifyMiddleware(app)
>>> app = XHTMLValidatorMiddleware(app)
>>> app = JSONValidatorMiddleware(app)

The middleware in this package buffer the output internally (this violates the PEP 333 specification, but it seems unavoidable), so it is best to use them near the top of the middleware stack.

Metadata

Release files for strainer 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for strainer 0.1.4
File Size Uploaded Provenance
strainer-0.1.4.tar.gz 22.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for strainer 0.1.4
File Interpreter ABI Platform
strainer-0.1.4-py2.6.egg Legacy Egg format - - Details

Total release size: 107.4 kB

Release files / strainer-0.1.4.tar.gz

Download URL strainer-0.1.4.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
04d264a0ed2cc206a719e61813474c310473fa1eaba53e193421ec5d1420019c
BLAKE2b-256 checksum
How to use checksums
904d8aee37366e6096dd54eb420781d0b46bcbf06fbd7fde9b8780643be6ed41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / strainer-0.1.4-py2.6.egg

Download URL strainer-0.1.4-py2.6.egg
Size 85.2 kB
Tags Egg
SHA-256 checksum
How to use checksums
7174ca16dab81397cd57387ae4c13ed21038d26a6f135caec224c0b17d34d485
BLAKE2b-256 checksum
How to use checksums
69bc702d65d61ba5d3fc8df7024f57e54fd1c9a64341787db25b5d4538be18d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for strainer 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page