summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-11-17 20:57:40 +0100
committerGitHub <noreply@github.com>2020-11-17 23:57:40 +0400
commit4c65505f1dd420a15eb7bbcd1fc84f4cee701234 (patch)
treef16147bf4e76d5f2fa19769902bb7b8a3d66dcf7
parent993bcb778615116d910ae187c7bdab1389dbb240 (diff)
downloadurllib3-4c65505f1dd420a15eb7bbcd1fc84f4cee701234.tar.gz
Remove Python 2 related code from src/urllib3/connectionpool.py (#2066)
-rw-r--r--src/urllib3/connectionpool.py38
1 files changed, 5 insertions, 33 deletions
diff --git a/src/urllib3/connectionpool.py b/src/urllib3/connectionpool.py
index 9acf51ee..3f00d4f7 100644
--- a/src/urllib3/connectionpool.py
+++ b/src/urllib3/connectionpool.py
@@ -321,23 +321,12 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
self, url, f"Read timed out. (read timeout={timeout_value})"
)
- # See the above comment about EAGAIN in Python 3. In Python 2 we have
- # to specifically catch it and throw the timeout error
+ # See the above comment about EAGAIN in Python 3.
if hasattr(err, "errno") and err.errno in _blocking_errnos:
raise ReadTimeoutError(
self, url, f"Read timed out. (read timeout={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.7.4
- raise ReadTimeoutError(
- self, url, f"Read timed out. (read timeout={timeout_value})"
- )
-
def _make_request(
self, conn, method, url, timeout=_Default, chunked=False, **httplib_request_kw
):
@@ -365,7 +354,6 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
try:
self._validate_conn(conn)
except (SocketTimeout, BaseSSLError) as e:
- # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
raise
@@ -381,17 +369,12 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
# legitimately able to close the connection after sending a valid response.
# With this behaviour, the received response is still readable.
except BrokenPipeError:
- # Python 3
pass
except OSError as e:
- # Python 2 and macOS/Linux
- # EPIPE and ESHUTDOWN are BrokenPipeError on Python 2, and EPROTOTYPE is needed on macOS
+ # MacOS/Linux
+ # EPROTOTYPE is needed on macOS
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
- if e.errno not in {
- errno.EPIPE,
- errno.ESHUTDOWN,
- errno.EPROTOTYPE,
- }:
+ if e.errno != errno.EPROTOTYPE:
raise
# Reset the timeout for the recv() on the socket
@@ -414,18 +397,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
# Receive the response from the server
try:
- try:
- # Python 2.7, use buffering of HTTP responses
- httplib_response = conn.getresponse(buffering=True)
- except TypeError:
- # Python 3
- try:
- httplib_response = conn.getresponse()
- except BaseException as e:
- # Remove the TypeError from the exception chain in
- # Python 3 (including for exceptions like SystemExit).
- # Otherwise it looks like a bug in the code.
- raise e from None
+ httplib_response = conn.getresponse()
except (SocketTimeout, BaseSSLError, SocketError) as e:
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
raise