summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Pradet <quentin@pradet.me>2018-08-24 16:52:14 +0400
committerSeth M. Larson <sethmichaellarson@gmail.com>2018-08-24 07:52:14 -0500
commita6c11c13e4759797d7e31ace4b0ae9521fb16c06 (patch)
tree156b4ddfc0f976a102c6eace5675aea924749834
parentcb2159878f8b47c5b4bc6d159ae2857b85c0a197 (diff)
downloadurllib3-a6c11c13e4759797d7e31ace4b0ae9521fb16c06.tar.gz
Remove more Python 2.6 code (#1430)
-rw-r--r--dev-requirements.txt4
-rw-r--r--src/urllib3/connection.py10
-rw-r--r--src/urllib3/connectionpool.py2
-rw-r--r--src/urllib3/packages/ssl_match_hostname/_implementation.py3
-rw-r--r--test/test_response.py17
-rw-r--r--test/with_dummyserver/test_https.py8
-rw-r--r--test/with_dummyserver/test_socketlevel.py10
7 files changed, 15 insertions, 39 deletions
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 9a2a962a..abbe781a 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -8,4 +8,6 @@ PySocks==1.6.8
pkginfo==1.4.2
pytest-timeout==1.3.1
pytest==3.6.4
-gcp-devrel-py-tools==0.0.15 \ No newline at end of file
+# https://github.com/GoogleCloudPlatform/python-repo-tools/issues/23
+pylint<2.0;python_version<="2.7"
+gcp-devrel-py-tools==0.0.15
diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py
index 7c9a9f3b..f8bc8b6b 100644
--- a/src/urllib3/connection.py
+++ b/src/urllib3/connection.py
@@ -171,10 +171,7 @@ class HTTPConnection(_HTTPConnection, object):
def _prepare_conn(self, conn):
self.sock = conn
- # the _tunnel_host attribute was added in python 2.6.3 (via
- # http://hg.python.org/cpython/rev/0f57b30a152f) so pythons 2.6(0-2) do
- # not have them.
- if getattr(self, '_tunnel_host', None):
+ if self._tunnel_host:
# TODO: Fix tunnel so it doesn't depend on self.sock state.
self._tunnel()
# Mark this connection as not reusable
@@ -302,12 +299,9 @@ class VerifiedHTTPSConnection(HTTPSConnection):
def connect(self):
# Add certificate verification
conn = self._new_conn()
-
hostname = self.host
- if getattr(self, '_tunnel_host', None):
- # _tunnel_host was added in Python 2.6.3
- # (See: http://hg.python.org/cpython/rev/0f57b30a152f)
+ if self._tunnel_host:
self.sock = conn
# Calls self._set_hostport(), so self.host is
# self._tunnel_host below.
diff --git a/src/urllib3/connectionpool.py b/src/urllib3/connectionpool.py
index 8e58fa74..f7a8f193 100644
--- a/src/urllib3/connectionpool.py
+++ b/src/urllib3/connectionpool.py
@@ -313,7 +313,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
# Catch possible read timeouts thrown as SSL errors. If not the
# case, rethrow the original. We need to do this because of:
# http://bugs.python.org/issue10272
- if 'timed out' in str(err) or 'did not complete (read)' in str(err): # Python 2.6
+ if 'timed out' in str(err) or 'did not complete (read)' in str(err): # Python < 2.7.4
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
def _make_request(self, conn, method, url, timeout=_Default, chunked=False,
diff --git a/src/urllib3/packages/ssl_match_hostname/_implementation.py b/src/urllib3/packages/ssl_match_hostname/_implementation.py
index 1fd42f38..d6e66c01 100644
--- a/src/urllib3/packages/ssl_match_hostname/_implementation.py
+++ b/src/urllib3/packages/ssl_match_hostname/_implementation.py
@@ -9,8 +9,7 @@ import sys
# ipaddress has been backported to 2.6+ in pypi. If it is installed on the
# system, use it to handle IPAddress ServerAltnames (this was added in
# python-3.5) otherwise only do DNS matching. This allows
-# backports.ssl_match_hostname to continue to be used all the way back to
-# python-2.4.
+# backports.ssl_match_hostname to continue to be used in Python 2.7.
try:
import ipaddress
except ImportError:
diff --git a/test/test_response.py b/test/test_response.py
index 0b347c25..79a87900 100644
--- a/test/test_response.py
+++ b/test/test_response.py
@@ -291,23 +291,6 @@ class TestResponse(object):
while not br.closed:
br.read(5)
- def test_io_readinto(self):
- # This test is necessary because in py2.6, `readinto` doesn't get called
- # in `test_io_bufferedreader` like it does for all the other python
- # versions. Probably this is because the `io` module in py2.6 is an
- # old version that has a different underlying implementation.
-
- fp = BytesIO(b'foo')
- resp = HTTPResponse(fp, preload_content=False)
-
- barr = bytearray(3)
- assert resp.readinto(barr) == 3
- assert b'foo' == barr
-
- # The reader should already be empty, so this should read nothing.
- assert resp.readinto(barr) == 0
- assert b'foo' == barr
-
def test_streaming(self):
fp = BytesIO(b'foo')
resp = HTTPResponse(fp, preload_content=False)
diff --git a/test/with_dummyserver/test_https.py b/test/with_dummyserver/test_https.py
index 41c1d5a7..082ede96 100644
--- a/test/with_dummyserver/test_https.py
+++ b/test/with_dummyserver/test_https.py
@@ -38,6 +38,7 @@ from urllib3.exceptions import (
SystemTimeWarning,
InsecurePlatformWarning,
MaxRetryError,
+ ProtocolError,
)
from urllib3.packages import six
from urllib3.util.timeout import Timeout
@@ -101,7 +102,12 @@ class TestHTTPS(HTTPSDummyServerTestCase):
'invalid certificate chain' in str(e) or
'unknown Cert Authority' in str(e) or
# https://github.com/urllib3/urllib3/issues/1422
- 'connection closed via error' in str(e)):
+ 'connection closed via error' in str(e) or
+ 'WSAECONNRESET' in str(e)):
+ raise
+ except ProtocolError as e:
+ # https://github.com/urllib3/urllib3/issues/1422
+ if not ('An existing connection was forcibly closed by the remote host' in str(e)):
raise
def test_verified(self):
diff --git a/test/with_dummyserver/test_socketlevel.py b/test/with_dummyserver/test_socketlevel.py
index a1896cfd..ec2f01d2 100644
--- a/test/with_dummyserver/test_socketlevel.py
+++ b/test/with_dummyserver/test_socketlevel.py
@@ -639,13 +639,6 @@ class TestSocketClosing(SocketDummyServerTestCase):
def test_closing_response_actually_closes_connection(self):
done_closing = Event()
complete = Event()
- # The insane use of this variable here is to get around the fact that
- # Python 2.6 does not support returning a value from Event.wait(). This
- # means we can't tell if an event timed out, so we can't use the timing
- # out of the 'complete' event to determine the success or failure of
- # the test. Python 2 also doesn't have the nonlocal statement, so we
- # can't write directly to this variable, only mutate it. Hence: list.
- successful = []
def socket_handler(listener):
sock = listener.accept()[0]
@@ -667,7 +660,6 @@ class TestSocketClosing(SocketDummyServerTestCase):
sock.settimeout(1)
new_data = sock.recv(65536)
self.assertFalse(new_data)
- successful.append(True)
sock.close()
complete.set()
@@ -680,7 +672,7 @@ class TestSocketClosing(SocketDummyServerTestCase):
response.close()
done_closing.set() # wait until the socket in our pool gets closed
- complete.wait(timeout=1)
+ successful = complete.wait(timeout=1)
if not successful:
self.fail("Timed out waiting for connection close")