flake8 cleanups

This commit is contained in:
Chris Dent
2013-11-05 20:57:00 +00:00
parent e9c515602c
commit 8a24b86c0e
7 changed files with 11 additions and 13 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -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()

View File

@@ -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):

View File

@@ -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

View File

@@ -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:

View File

@@ -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