Skip to content

Commit 01353d3

Browse files
committedJul 23, 2024
Invert major version check
1 parent 4e38364 commit 01353d3

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed
 

‎src/requests/compat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
# Detect which major version of urllib3 is being used.
1919
try:
20-
is_urllib3_2 = int(urllib3_version.split(".")[0]) == 2
20+
is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
2121
except (TypeError, AttributeError):
2222
# If we can't discern a version, prefer old functionality.
23-
is_urllib3_2 = False
23+
is_urllib3_1 = True
2424

2525
# -------------------
2626
# Character Detection

‎src/requests/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
getproxies,
3939
getproxies_environment,
4040
integer_types,
41-
is_urllib3_2,
41+
is_urllib3_1,
4242
)
4343
from .compat import parse_http_list as _parse_list_header
4444
from .compat import (
@@ -137,8 +137,8 @@ def super_len(o):
137137
total_length = None
138138
current_position = 0
139139

140-
if is_urllib3_2 and isinstance(o, str):
141-
# urllib3 2.x treats all strings as utf-8 instead
140+
if not is_urllib3_1 and isinstance(o, str):
141+
# urllib3 2.x+ treats all strings as utf-8 instead
142142
# of latin-1 (iso-8859-1) like http.client.
143143
o = o.encode("utf-8")
144144

‎tests/test_requests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
builtin_str,
2626
cookielib,
2727
getproxies,
28-
is_urllib3_2,
28+
is_urllib3_1,
2929
urlparse,
3030
)
3131
from requests.cookies import cookiejar_from_dict, morsel_to_cookie
@@ -2961,7 +2961,7 @@ def test_content_length_for_bytes_data(httpbin):
29612961

29622962

29632963
@pytest.mark.skipif(
2964-
not is_urllib3_2,
2964+
is_urllib3_1,
29652965
reason="urllib3 2.x encodes all strings to utf-8, urllib3 1.x uses latin-1",
29662966
)
29672967
def test_content_length_for_string_data_counts_bytes(httpbin):

0 commit comments

Comments
 (0)
Please sign in to comment.