This is basic flake8 testing without any 'hacking' extensions. We may wish to add those later, but for the time being this code is so much of its own particular style that that would be painful. In any case, the hacking rules aren't that great. In the process some documentation adjustments were made while fixing line lenghts. A dead link was removed.
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""Common code of urllib3 and requests intercepts."""
|
|
|
|
import os
|
|
import sys
|
|
|
|
from . import WSGI_HTTPConnection, WSGI_HTTPSConnection, wsgi_fake_socket
|
|
|
|
|
|
wsgi_fake_socket.settimeout = lambda self, timeout: None
|
|
|
|
|
|
def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
|
|
HTTPConnection, HTTPSConnection):
|
|
|
|
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):
|
|
is_verified = True
|
|
|
|
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():
|
|
if 'http_proxy' in os.environ or 'https_proxy' in os.environ:
|
|
raise RuntimeError(
|
|
'http_proxy or https_proxy set in environment, please unset')
|
|
HTTPConnectionPool.ConnectionCls = HTTP_WSGIInterceptor
|
|
HTTPSConnectionPool.ConnectionCls = HTTPS_WSGIInterceptor
|
|
|
|
def uninstall():
|
|
HTTPConnectionPool.ConnectionCls = HTTPConnection
|
|
HTTPSConnectionPool.ConnectionCls = HTTPSConnection
|
|
|
|
return install, uninstall
|