From d34e64f7640fb6e8f22ed74d05e19d8aae0dadc3 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 29 Jun 2016 13:49:21 -0400 Subject: [PATCH] Don't use six when testing httplib Otherwise monkeypatching get confused and will not work and the tests will fail. An effort was made to use the six http_client always (both in tests and the interceptor) but this led to infinite recursion, so going for the lame fix here. The functionality has always worked (as long as six wasn't involved) this is just getting things working in tests. --- test/test_interceptor.py | 6 +++++- wsgi_intercept/http_client_intercept.py | 9 +++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/test_interceptor.py b/test/test_interceptor.py index de0e9ca..05c10e4 100644 --- a/test/test_interceptor.py +++ b/test/test_interceptor.py @@ -11,7 +11,11 @@ import py.test import requests import urllib3 from httplib2 import Http, ServerNotFoundError -from six.moves import http_client +# don't use six as the monkey patching gets confused +try: + import http.client as http_client +except ImportError: + import httplib as http_client from six.moves.urllib.request import urlopen from six.moves.urllib.error import URLError diff --git a/wsgi_intercept/http_client_intercept.py b/wsgi_intercept/http_client_intercept.py index c7f9ca8..56d930c 100644 --- a/wsgi_intercept/http_client_intercept.py +++ b/wsgi_intercept/http_client_intercept.py @@ -19,16 +19,13 @@ except ImportError: HTTPSConnection as OriginalHTTPSConnection ) -HTTPInterceptorMixin = WSGI_HTTPConnection -HTTPSInterceptorMixin = WSGI_HTTPSConnection - -class HTTP_WSGIInterceptor(HTTPInterceptorMixin, http_lib.HTTPConnection): +class HTTP_WSGIInterceptor(WSGI_HTTPConnection, http_lib.HTTPConnection): pass -class HTTPS_WSGIInterceptor(HTTPSInterceptorMixin, http_lib.HTTPSConnection, - HTTP_WSGIInterceptor): +class HTTPS_WSGIInterceptor(WSGI_HTTPSConnection, http_lib.HTTPSConnection, + HTTP_WSGIInterceptor): def __init__(self, host, **kwargs): self.host = host