Invert major version check
This commit is contained in:
@@ -17,10 +17,10 @@ from urllib3 import __version__ as urllib3_version
|
||||
|
||||
# Detect which major version of urllib3 is being used.
|
||||
try:
|
||||
is_urllib3_2 = int(urllib3_version.split(".")[0]) == 2
|
||||
is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
|
||||
except (TypeError, AttributeError):
|
||||
# If we can't discern a version, prefer old functionality.
|
||||
is_urllib3_2 = False
|
||||
is_urllib3_1 = True
|
||||
|
||||
# -------------------
|
||||
# Character Detection
|
||||
|
||||
@@ -38,7 +38,7 @@ from .compat import (
|
||||
getproxies,
|
||||
getproxies_environment,
|
||||
integer_types,
|
||||
is_urllib3_2,
|
||||
is_urllib3_1,
|
||||
)
|
||||
from .compat import parse_http_list as _parse_list_header
|
||||
from .compat import (
|
||||
@@ -137,8 +137,8 @@ def super_len(o):
|
||||
total_length = None
|
||||
current_position = 0
|
||||
|
||||
if is_urllib3_2 and isinstance(o, str):
|
||||
# urllib3 2.x treats all strings as utf-8 instead
|
||||
if not is_urllib3_1 and isinstance(o, str):
|
||||
# urllib3 2.x+ treats all strings as utf-8 instead
|
||||
# of latin-1 (iso-8859-1) like http.client.
|
||||
o = o.encode("utf-8")
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ from requests.compat import (
|
||||
builtin_str,
|
||||
cookielib,
|
||||
getproxies,
|
||||
is_urllib3_2,
|
||||
is_urllib3_1,
|
||||
urlparse,
|
||||
)
|
||||
from requests.cookies import cookiejar_from_dict, morsel_to_cookie
|
||||
@@ -2961,7 +2961,7 @@ def test_content_length_for_bytes_data(httpbin):
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not is_urllib3_2,
|
||||
is_urllib3_1,
|
||||
reason="urllib3 2.x encodes all strings to utf-8, urllib3 1.x uses latin-1",
|
||||
)
|
||||
def test_content_length_for_string_data_counts_bytes(httpbin):
|
||||
|
||||
Reference in New Issue
Block a user