Enforce flake8-2020
We don't know if we'll ever have a Python 4 or if six.PY3 will include
Python 4+ or if six will still be of any use by then, but I'd like
avoiding having to think about it in reviews. :)
MODIFY
noxfile.py
noxfile.py
@@ -111,7 +111,7 @@ def blacken(session):
@nox.session
def lint(session):
- session.install("flake8", "black", "mypy")
+ session.install("flake8", "flake8-2020", "black", "mypy")
session.run("flake8", "--version")
session.run("black", "--version")
session.run("mypy", "--version")

MODIFY
src/urllib3/_collections.py
src/urllib3/_collections.py
@@ -18,7 +18,8 @@ except ImportError: # Platform-specific: No threads available
from collections import OrderedDict
from .exceptions import InvalidHeader
-from .packages.six import ensure_str, iterkeys, itervalues, PY3
+from .packages import six
+from .packages.six import iterkeys, itervalues
__all__ = ["RecentlyUsedContainer", "HTTPHeaderDict"]
@@ -154,7 +155,7 @@ class HTTPHeaderDict(MutableMapping):
def __getitem__(self, key):
val = self._container[key.lower()]
- return ", ".join([ensure_str(v, "ascii") for v in val[1:]])
+ return ", ".join([six.ensure_str(v, "ascii") for v in val[1:]])
def __delitem__(self, key):
del self._container[key.lower()]
@@ -174,7 +175,7 @@ class HTTPHeaderDict(MutableMapping):
def __ne__(self, other):
return not self.__eq__(other)
- if not PY3: # Python 2
+ if six.PY2: # Python 2
iterkeys = MutableMapping.iterkeys
itervalues = MutableMapping.itervalues

MODIFY
src/urllib3/poolmanager.py
src/urllib3/poolmanager.py
@@ -20,7 +20,6 @@ from .request import RequestMethods
from .util.url import parse_url
from .util.retry import Retry
from .util.proxy import connection_requires_http_tunnel
-from .packages.six import PY3
__all__ = ["PoolManager", "ProxyManager", "proxy_from_url"]
@@ -346,7 +345,7 @@ class PoolManager(RequestMethods):
if self.proxy.scheme != "https":
return
- if not PY3 and not self.proxy_config.use_forwarding_for_https:
+ if six.PY2 and not self.proxy_config.use_forwarding_for_https:
raise ProxySchemeUnsupported(
"Contacting HTTPS destinations through HTTPS proxies "
"'via CONNECT tunnels' is not supported in Python 2"

MODIFY
src/urllib3/response.py
src/urllib3/response.py
@@ -24,7 +24,7 @@ from .exceptions import (
HTTPError,
SSLError,
)
-from .packages.six import string_types as basestring, PY3
+from .packages import six
from .connection import HTTPException, BaseSSLError
from .util.response import is_fp_closed, is_response_to_head
@@ -233,7 +233,7 @@ class HTTPResponse(io.IOBase):
self.msg = msg
self._request_url = request_url
- if body and isinstance(body, (basestring, bytes)):
+ if body and isinstance(body, (six.string_types, bytes)):
self._body = body
self._pool = pool
@@ -589,11 +589,11 @@ class HTTPResponse(io.IOBase):
headers = r.msg
if not isinstance(headers, HTTPHeaderDict):
- if PY3:
- headers = HTTPHeaderDict(headers.items())
- else:
+ if six.PY2:
# Python 2.7
headers = HTTPHeaderDict.from_httplib(headers)
+ else:
+ headers = HTTPHeaderDict(headers.items())
# HTTPResponse objects in Python 3 don't have a .strict attribute
strict = getattr(r, "strict", 0)

MODIFY
src/urllib3/util/ssltransport.py
src/urllib3/util/ssltransport.py
@@ -3,7 +3,7 @@ import socket
import io
from urllib3.exceptions import ProxySchemeUnsupported
-from urllib3.packages.six import PY3
+from urllib3.packages import six
SSL_BLOCKSIZE = 16384
@@ -30,7 +30,7 @@ class SSLTransport:
"""
if not hasattr(ssl_context, "wrap_bio"):
- if not PY3:
+ if six.PY2:
raise ProxySchemeUnsupported(
"TLS in TLS requires SSLContext.wrap_bio() which isn't "
"supported on Python 2"

Enforce flake8-2020

We don't know if we'll ever have a Python 4 or if six.PY3 will include
Python 4+ or if six will still be of any use by then, but I'd like
avoiding having to think about it in reviews. :)