Context manager based WSGI interception.
Interceptor for httplib and http.client.
Interceptor for httplib2.
A convenience class over the guts of wsgi_intercept.
An Interceptor subclass provides a clean entry point to the wsgi_intercept functionality in two ways: by encapsulating the interception addition and removal in methods and by providing a context manager that automates the process of addition and removal.
Each Interceptor subclass is associated with a specific http library.
Each class may be passed a url or a host and a port. If no args are passed a hostname will be automatically generated and the resulting url will be returned by the context manager.
Interceptor for requests.
Interceptor for requests.
Interceptor for urllib2 and urllib.request.
Example using httplib2, others are much the same:
import httplib2
from wsgi_intercept.interceptor import Httplib2Interceptor
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [b'Whee']
def make_app():
return app
http = httplib2.Http()
with Httplib2Interceptor(make_app, host='localhost', port=80) as url:
resp, content = http.request(url)
assert content == b'Whee'