File: requests_intercept.py

package info (click to toggle)
python-wsgi-intercept 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 288 kB
  • ctags: 201
  • sloc: python: 710; makefile: 180
file content (29 lines) | stat: -rw-r--r-- 816 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Intercept HTTP connections that use `requests <http://docs.python-requests.org/en/latest/>`_.
"""

from . import WSGI_HTTPConnection, WSGI_HTTPSConnection, wsgi_fake_socket
from urllib3.connectionpool import (HTTPConnectionPool,
        HTTPSConnectionPool)
from urllib3.connection import (HTTPConnection,
        HTTPSConnection)


wsgi_fake_socket.settimeout = lambda self, timeout: None


class HTTP_WSGIInterceptor(WSGI_HTTPConnection, HTTPConnection):
    pass


class HTTPS_WSGIInterceptor(WSGI_HTTPSConnection, HTTPSConnection):
    pass


def install():
    HTTPConnectionPool.ConnectionCls = HTTP_WSGIInterceptor
    HTTPSConnectionPool.ConnectionCls = HTTPS_WSGIInterceptor


def uninstall():
    HTTPConnectionPool.ConnectionCls = HTTPConnection
    HTTPSConnectionPool.ConnectionCls = HTTPSConnection