Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more Python 2.6 code #1430

Merged
merged 7 commits into from Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion dev-requirements.txt
Expand Up @@ -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
# https://github.com/GoogleCloudPlatform/python-repo-tools/issues/23
pylint<2.0;python_version<="2.7"
gcp-devrel-py-tools==0.0.15
10 changes: 2 additions & 8 deletions src/urllib3/connection.py
Expand Up @@ -171,10 +171,7 @@ def _new_conn(self):

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
Expand Down Expand Up @@ -302,12 +299,9 @@ def set_cert(self, key_file=None, cert_file=None,
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.
Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/connectionpool.py
Expand Up @@ -313,7 +313,7 @@ def _raise_timeout(self, err, url, timeout_value):
# 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,
Expand Down
3 changes: 1 addition & 2 deletions src/urllib3/packages/ssl_match_hostname/_implementation.py
Expand Up @@ -9,8 +9,7 @@
# 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:
Expand Down
17 changes: 0 additions & 17 deletions test/test_response.py
Expand Up @@ -291,23 +291,6 @@ def test_io_bufferedreader(self):
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)
Expand Down
8 changes: 7 additions & 1 deletion test/with_dummyserver/test_https.py
Expand Up @@ -38,6 +38,7 @@
SystemTimeWarning,
InsecurePlatformWarning,
MaxRetryError,
ProtocolError,
)
from urllib3.packages import six
from urllib3.util.timeout import Timeout
Expand Down Expand Up @@ -101,7 +102,12 @@ def test_client_no_intermediate(self):
'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):
Expand Down
10 changes: 1 addition & 9 deletions test/with_dummyserver/test_socketlevel.py
Expand Up @@ -639,13 +639,6 @@ def socket_handler(listener):
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]
Expand All @@ -667,7 +660,6 @@ def socket_handler(listener):
sock.settimeout(1)
new_data = sock.recv(65536)
self.assertFalse(new_data)
successful.append(True)
sock.close()
complete.set()

Expand All @@ -680,7 +672,7 @@ def socket_handler(listener):
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")

Expand Down