Skip to main content

Adaptable request interfaces.

Project description

The motivation for this package is to encourage the use of request type adaptation instead of depending on packages with request type definitions.

Instead of subclassing the request interface, we encourage an adaptation pattern:

>>> from repoze.bfg.interfaces import IRequest
>>> IGZipRequest = IRequest({'Accept-Encoding': 'gzip'})

An event handler listens for the INewRequest event and automatically marks the request with interfaces as needed to adapt the request to the request types that it may apply for.

To complete the example above, a request would come in with an HTTP environment like the following:

{‘Accept-Encoding’: ‘compress, gzip’}

Since we’ve previouly adapted the request to an accept-encoding of ‘gzip’, the adaptation machinery will mark the interface such that this environment will match the IGZipRequest interface.

This would be an alternative to subclassing, where we would manually have to set up an event listener that interprets the request environment and marks the request with the interface.

>>> class IGZipRequest(IRequest):
...     """Marker interface for requests for gzipped response."""


Stefan Eletzhofer <> and Malthe Borch <>.

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

repoze.bfg.httprequest-0.1.tar.gz (4.9 kB view hashes)

Uploaded Source

Supported by

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