Skip to content

Commit ae7f8bb

Browse files
hugovksethmlarson
authored andcommitted
Fix for Python 4 (urllib3#1669)
1 parent 6a626be commit ae7f8bb

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

src/urllib3/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class HTTPConnection(_HTTPConnection, object):
9999
is_verified = False
100100

101101
def __init__(self, *args, **kw):
102-
if six.PY3:
102+
if not six.PY2:
103103
kw.pop("strict", None)
104104

105105
# Pre-set source_address.

src/urllib3/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ def format_header_param_rfc2231(name, value):
4747
else:
4848
return result
4949

50-
if not six.PY3: # Python 2:
50+
if six.PY2: # Python 2:
5151
value = value.encode("utf-8")
5252

5353
# encode_rfc2231 accepts an encoded string and returns an ascii-encoded
5454
# string in Python 2 but accepts and returns unicode strings in Python 3
5555
value = email.utils.encode_rfc2231(value, "utf-8")
5656
value = "%s*=%s" % (name, value)
5757

58-
if not six.PY3: # Python 2:
58+
if six.PY2: # Python 2:
5959
value = value.decode("utf-8")
6060

6161
return value

src/urllib3/filepost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def choose_boundary():
1717
Our embarrassingly-simple replacement for mimetools.choose_boundary.
1818
"""
1919
boundary = binascii.hexlify(os.urandom(16))
20-
if six.PY3:
20+
if not six.PY2:
2121
boundary = boundary.decode("ascii")
2222
return boundary
2323

src/urllib3/util/ssl_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def is_ipaddress(hostname):
385385
:param str hostname: Hostname to examine.
386386
:return: True if the hostname is an IP address, False otherwise.
387387
"""
388-
if six.PY3 and isinstance(hostname, bytes):
388+
if not six.PY2 and isinstance(hostname, bytes):
389389
# IDN A-label bytes are ASCII compatible.
390390
hostname = hostname.decode("ascii")
391391
return bool(IPV4_RE.match(hostname) or BRACELESS_IPV6_ADDRZ_RE.match(hostname))

test/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def onlyPy2(test):
6262
@functools.wraps(test)
6363
def wrapper(*args, **kwargs):
6464
msg = "{name} requires Python 2.x to run".format(name=test.__name__)
65-
if six.PY3:
65+
if not six.PY2:
6666
pytest.skip(msg)
6767
return test(*args, **kwargs)
6868

@@ -75,7 +75,7 @@ def onlyPy3(test):
7575
@functools.wraps(test)
7676
def wrapper(*args, **kwargs):
7777
msg = "{name} requires Python3.x to run".format(name=test.__name__)
78-
if not six.PY3:
78+
if six.PY2:
7979
pytest.skip(msg)
8080
return test(*args, **kwargs)
8181

test/appengine/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def sandbox(testbed):
7272
def pytest_ignore_collect(path, config):
7373
"""Skip App Engine tests in python 3 or if no SDK is available."""
7474
if "appengine" in str(path):
75-
if six.PY3:
75+
if not six.PY2:
7676
return True
7777
if not os.environ.get("GAE_SDK_PATH"):
7878
return True

test/test_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def test_string_enforcement(self, d):
344344
HTTPHeaderDict({3: 3})
345345

346346
@pytest.mark.skipif(
347-
six.PY3, reason="python3 has a different internal header implementation"
347+
not six.PY2, reason="python3 has a different internal header implementation"
348348
)
349349
def test_from_httplib_py2(self):
350350
msg = """

0 commit comments

Comments
 (0)