Skip to content
Myr

Invert major version check

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by Nate Prewitt · parent 4e38364 · Browse files · 3 files+7 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+7 added−7 removed

  • tests:+2 added−2 removed
  • other:+5 added−5 removed

3 files+7 added−7 removed

modified:src/requests/compat.py+2 added-2 removed
15 unmodified lines
16from urllib3 import __version__ as urllib3_version1718# Detect which major version of urllib3 is being used.19try:20 is_urllib3_2 = int(urllib3_version.split(".")[0]) == 220 is_urllib3_1 = int(urllib3_version.split(".")[0]) == 121except (TypeError, AttributeError):22 # If we can't discern a version, prefer old functionality.23 is_urllib3_2 = False23 is_urllib3_1 = True2425# -------------------26# Character Detection27# -------------------
79 unmodified lines
modified:src/requests/utils.py+3 added-3 removed
36 unmodified lines
37 bytes,38 getproxies,39 getproxies_environment,40 integer_types,41 is_urllib3_2,41 is_urllib3_1,42)43from .compat import parse_http_list as _parse_list_header44from .compat import (45 proxy_bypass,
90 unmodified lines
136def super_len(o):137 total_length = None138 current_position = 0139140 if is_urllib3_2 and isinstance(o, str):141 # urllib3 2.x treats all strings as utf-8 instead140 if not is_urllib3_1 and isinstance(o, str):141 # urllib3 2.x+ treats all strings as utf-8 instead142 # of latin-1 (iso-8859-1) like http.client.143 o = o.encode("utf-8")144145 if hasattr(o, "__len__"):
954 unmodified lines
modified:tests/test_requests.py+2 added-2 removed
23 unmodified lines
24 MutableMapping,25 builtin_str,26 cookielib,27 getproxies,28 is_urllib3_2,28 is_urllib3_1,29 urlparse,30)31from requests.cookies import cookiejar_from_dict, morsel_to_cookie32from requests.exceptions import (
2927 unmodified lines
2960 assert p.headers["Content-Length"] == length296129622963@pytest.mark.skipif(2964 not is_urllib3_2,2964 is_urllib3_1,2965 reason="urllib3 2.x encodes all strings to utf-8, urllib3 1.x uses latin-1",2966)2967def test_content_length_for_string_data_counts_bytes(httpbin):2968 data = "This is a string containing multi-byte UTF-8 ☃️"
15 unmodified lines