Remove more Python 2.6 code
MODIFY
dev-requirements.txt
dev-requirements.txt
@@ -8,4 +8,6 @@ PySocks==1.6.8
pkginfo==1.4.2
pytest-timeout==1.3.1
pytest==3.6.4
+# https://github.com/GoogleCloudPlatform/python-repo-tools/issues/23
+pylint<2.0;python_version<="2.7"
gcp-devrel-py-tools==0.0.15

MODIFY
src/urllib3/connection.py
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.

MODIFY
src/urllib3/connectionpool.py
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,

MODIFY
src/urllib3/packages/ssl_match_hostname/_implementation.py
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:

MODIFY
test/test_response.py
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)

MODIFY
test/with_dummyserver/test_https.py
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):

MODIFY
test/with_dummyserver/test_socketlevel.py
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")

Remove more Python 2.6 code (#1430)