from httptoolkit_intercept import preload_real_module preload_real_module('httplib2') import httplib2, os, functools # Re-export all public fields from httplib2 import * # Load a few extra notable private fields, for max compatibility from httplib2 import __file__, __doc__ _certPath = os.environ['SSL_CERT_FILE'] # Ensure all connections trust our cert: _http_init = httplib2.Http.__init__ @functools.wraps(_http_init) def _new_http_init(self, *k, **kw): kList = list(k) if len(kList) > 3: kList[3] = _certPath else: kw['ca_certs'] = _certPath _http_init(self, *kList, **kw) httplib2.Http.__init__ = _new_http_init
from httptoolkit_intercept import preload_real_module preload_real_module('stripe') import stripe, os stripe.ca_bundle_path = os.environ['SSL_CERT_FILE'] # Re-export all public fields from Stripe from stripe import * # Load a few extra notable private fields, for max compatibility from stripe import __path__, __file__, __doc__
from httptoolkit_intercept import preload_real_module preload_real_module('http', 'http.client') import http.client, os, functools # Re-export all public fields from http.client import * # Load a few extra notable private fields, for max compatibility from http.client import __file__, __doc__ _httpProxy = os.environ['HTTP_PROXY'] [_proxyHost, _proxyPort] = _httpProxy.split('://')[1].split(':') _certPath = os.environ['SSL_CERT_FILE'] # Redirect and then tunnel all plain HTTP connections: _http_connection_init = HTTPConnection.__init__ @functools.wraps(_http_connection_init) def _new_http_connection_init(self, host, port=80, *k, **kw): _http_connection_init(self, _proxyHost, int(_proxyPort), *k, **kw) self.set_tunnel(host, port) HTTPConnection.__init__ = _new_http_connection_init def _build_default_context(): import ssl context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) context.options |= ssl.OP_NO_SSLv2 context.options |= ssl.OP_NO_SSLv3 return context # Redirect & tunnel HTTPS connections, and inject our CA certificate:
from httptoolkit_intercept import preload_real_module preload_real_module('hgdemandimport') import hgdemandimport # Re-export all other public fields from hgdemandimport import * # Disable hgdemandimport entirely. This is an optional optimization used by hg, which doesn't play # nicely with HTTP Toolkit's import hooks, making hg unusable. hgdemandimport.enable = lambda: None