From 8a24b86c0e2b2ba08534310a205c7bac6b29dc95 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 5 Nov 2013 20:57:00 +0000 Subject: [PATCH] flake8 cleanups --- test/test_http_client.py | 3 +-- test/test_httplib2.py | 3 ++- test/test_wsgi_compliance.py | 7 ++++--- wsgi_intercept/__init__.py | 2 +- wsgi_intercept/http_client_intercept.py | 2 -- wsgi_intercept/httplib2_intercept.py | 4 ++-- wsgi_intercept/requests_intercept.py | 3 +-- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/test/test_http_client.py b/test/test_http_client.py index 05536b1..413f41f 100644 --- a/test/test_http_client.py +++ b/test/test_http_client.py @@ -1,5 +1,3 @@ -import pytest -import sys from wsgi_intercept import http_client_intercept import wsgi_intercept from test import wsgi_app @@ -9,6 +7,7 @@ try: except ImportError: import httplib as http_lib + def teardown_module(): """Ensure overrides removed.""" http_uninstall(443) diff --git a/test/test_httplib2.py b/test/test_httplib2.py index dec7440..157fbc4 100644 --- a/test/test_httplib2.py +++ b/test/test_httplib2.py @@ -21,7 +21,8 @@ def uninstall(): def test_success(): install() http = httplib2.Http() - resp, content = http.request('http://some_hopefully_nonexistant_domain:80/') + resp, content = http.request( + 'http://some_hopefully_nonexistant_domain:80/') assert content == b'WSGI intercept successful!\n' assert wsgi_app.success() uninstall() diff --git a/test/test_wsgi_compliance.py b/test/test_wsgi_compliance.py index f52cfec..40d82ab 100644 --- a/test/test_wsgi_compliance.py +++ b/test/test_wsgi_compliance.py @@ -54,7 +54,8 @@ def test_script_name(): wsgi_app.create_mi, script_name='/funky') http = httplib2.Http() - response, content = http.request('http://some_hopefully_nonexistant_domain/funky/boom/baz', 'GET') + response, content = http.request( + 'http://some_hopefully_nonexistant_domain/funky/boom/baz') internal_env = wsgi_app.get_internals() assert internal_env['SCRIPT_NAME'] == '/funky' @@ -63,7 +64,7 @@ def test_script_name(): http_uninstall() -py.test.mark.xfail(sys.version_info[0] == 2 and sys.version_info[1] <= 6, +@py.test.mark.xfail(sys.version_info[0] == 2 and sys.version_info[1] <= 6, reason='works okay on 2.7 and beyond. why?') def test_encoding_errors(): http_install() @@ -74,7 +75,7 @@ def test_encoding_errors(): http = httplib2.Http() with py.test.raises(UnicodeEncodeError): response, content = http.request( - 'http://some_hopefully_nonexistant_domain/boom/baz', 'GET', + 'http://some_hopefully_nonexistant_domain/boom/baz', headers={'Accept': u'application/\u2603'}) http_uninstall() diff --git a/wsgi_intercept/__init__.py b/wsgi_intercept/__init__.py index fe3c0cf..300151e 100644 --- a/wsgi_intercept/__init__.py +++ b/wsgi_intercept/__init__.py @@ -399,7 +399,7 @@ class wsgi_fake_socket: try: self.inp.write(content) - except TypeError as exc: + except TypeError: self.inp.write(content.encode('utf-8')) def close(self): diff --git a/wsgi_intercept/http_client_intercept.py b/wsgi_intercept/http_client_intercept.py index 119b29f..9cefde6 100644 --- a/wsgi_intercept/http_client_intercept.py +++ b/wsgi_intercept/http_client_intercept.py @@ -40,8 +40,6 @@ class HTTPS_WSGIInterceptor(HTTPSInterceptorMixin, http_lib.HTTPSConnection, HTTP_WSGIInterceptor.__init__(self, host, **kwargs) - - def install(): http_lib.HTTPConnection = HTTP_WSGIInterceptor http_lib.HTTPSConnection = HTTPS_WSGIInterceptor diff --git a/wsgi_intercept/httplib2_intercept.py b/wsgi_intercept/httplib2_intercept.py index 0691b8f..339efcc 100644 --- a/wsgi_intercept/httplib2_intercept.py +++ b/wsgi_intercept/httplib2_intercept.py @@ -23,7 +23,7 @@ class HTTP_WSGIInterceptorWithTimeout(InterceptorMixin, try: HTTPConnection.__init__(self, host, port=port, strict=strict, timeout=timeout, source_address=source_address) - except TypeError: # Python 2.6 doesn't have source_address + except TypeError: # Python 2.6 doesn't have source_address HTTPConnection.__init__(self, host, port=port, strict=strict, timeout=timeout) else: @@ -43,7 +43,7 @@ class HTTPS_WSGIInterceptorWithTimeout(InterceptorMixin, try: HTTPSConnection.__init__(self, host, port=port, strict=strict, timeout=timeout, source_address=source_address) - except TypeError: # Python 2.6 doesn't have source_address + except TypeError: # Python 2.6 doesn't have source_address HTTPSConnection.__init__(self, host, port=port, strict=strict, timeout=timeout) else: diff --git a/wsgi_intercept/requests_intercept.py b/wsgi_intercept/requests_intercept.py index f608ae9..860428c 100644 --- a/wsgi_intercept/requests_intercept.py +++ b/wsgi_intercept/requests_intercept.py @@ -2,13 +2,12 @@ intercept HTTP connections that use requests """ -import requests from . import WSGI_HTTPConnection, wsgi_fake_socket from requests.packages.urllib3.connectionpool import (HTTPConnectionPool, HTTPSConnectionPool) from requests.packages.urllib3.connection import (HTTPConnection, HTTPSConnection) -import sys + InterceptorMixin = WSGI_HTTPConnection wsgi_fake_socket.settimeout = lambda self, timeout: None