"""Intercept HTTP connections that use `requests <http://docs.python-requests.org/en/latest/>`_.
"""

from . import WSGI_HTTPConnection, WSGI_HTTPSConnection, wsgi_fake_socket
from requests.packages.urllib3.connectionpool import (HTTPConnectionPool,
        HTTPSConnectionPool)
from requests.packages.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

"""Intercept HTTP connections that use `requests <http://docs.python-requests.org/en/latest/>`_.
"""

import sys

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


wsgi_fake_socket.settimeout = lambda self, timeout: None


class HTTP_WSGIInterceptor(WSGI_HTTPConnection, HTTPConnection):
    def __init__(self, *args, **kwargs):
        if 'strict' in kwargs and sys.version_info > (3, 0):
            kwargs.pop('strict')
        WSGI_HTTPConnection.__init__(self, *args, **kwargs)
        HTTPConnection.__init__(self, *args, **kwargs)


class HTTPS_WSGIInterceptor(WSGI_HTTPSConnection, HTTPSConnection):
    def __init__(self, *args, **kwargs):
        if 'strict' in kwargs and sys.version_info > (3, 0):
            kwargs.pop('strict')
        WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
        HTTPSConnection.__init__(self, *args, **kwargs)


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


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

Deal with request's urllib3 being annoying about 'strict'
Deal with request's urllib3 being annoying about 'strict'

These changes are required to get tests to pass in python3.4 (and
presumably others).

This is entirely code from @sashahart, who had done the work earlier
to deal with with some Debian related issues uncovered by @thomasgoirand.

These changes will probably mean the debian packages will need to be
updated when the next version is released.
