test_utils.py
This file
Path
tests/test_utils.py
977 lines · 29.4 KiB · Python
Last changed by
Add more tests to prevent regression of CVE 2024 47081Arthur Woimbéebefore adoption5b4b64c
History of this fileTake it
The walk stopped after 200 commits: lines older than aae7801 point at it.
Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 1–2why, one step back1import copy2import filecmpAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 3why, one step back3import osCatch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 4why, one step back4import tarfileTime out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 5–6why, one step back5import zipfile6from collections import dequeAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 7why, one step back7from io import BytesIORemove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 8why, one step back8from unittest import mockTime out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 9–10why, one step back910import pytestAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 11why, one step back11Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 12why, one step back12from requests import compatAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 13why, one step back13from requests._internal_utils import unicode_is_asciiTime out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 14–16why, one step back14from requests.cookies import RequestsCookieJar15from requests.structures import CaseInsensitiveDict16from requests.utils import (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 17–25why, one step back17 _parse_content_type_header,18 add_dict_to_cookiejar,19 address_in_network,20 dotted_netmask,21 extract_zipped_paths,22 get_auth_from_url,23 get_encoding_from_headers,24 get_encodings_from_content,25 get_environ_proxies,Add more tests to prevent regression of CVE 2024 47081Arthur Woimbéebefore adoption5b4b64c
line 26why, one step back26 get_netrc_auth,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 27–45why, one step back27 guess_filename,28 guess_json_utf,29 is_ipv4_address,30 is_valid_cidr,31 iter_slices,32 parse_dict_header,33 parse_header_links,34 prepend_scheme_if_needed,35 requote_uri,36 select_proxy,37 set_environ,38 should_bypass_proxies,39 super_len,40 to_key_val_list,41 to_native_string,42 unquote_header_value,43 unquote_unreserved,44 urldefragauth,45)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 46–51why, one step back4647from .compat import StringIO, cStringIO484950class TestSuperLen:51 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 52–60why, one step back52 "stream, value",53 (54 (StringIO.StringIO, "Test"),55 (BytesIO, b"Test"),56 pytest.param(57 cStringIO, "Test", marks=pytest.mark.skipif("cStringIO is None")58 ),59 ),60 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 61–68why, one step back61 def test_io_streams(self, stream, value):62 """Ensures that we properly deal with different kinds of IO streams."""63 assert super_len(stream()) == 064 assert super_len(stream(value)) == 46566 def test_super_len_correctly_calculates_len_of_partially_read_file(self):67 """Ensure that we handle partially consumed file like objects."""68 s = StringIO.StringIO()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 69why, one step back69 s.write("foobarbogus")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 70–71why, one step back70 assert super_len(s) == 071Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 72why, one step back72 @pytest.mark.parametrize("error", [IOError, OSError])Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 73–74why, one step back73 def test_super_len_handles_files_raising_weird_errors_in_tell(self, error):74 """If tell() raises errors, assume the cursor is at position zero."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 75–76why, one step back7576 class BoomFile:Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 77–84why, one step back77 def __len__(self):78 return 57980 def tell(self):81 raise error()8283 assert super_len(BoomFile()) == 084Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 85why, one step back85 @pytest.mark.parametrize("error", [IOError, OSError])Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 86–87why, one step back86 def test_super_len_tell_ioerror(self, error):87 """Ensure that if tell gives an IOError super_len doesn't fail"""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 88–89why, one step back8889 class NoLenBoomFile:Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 90–98why, one step back90 def tell(self):91 raise error()9293 def seek(self, offset, whence):94 pass9596 assert super_len(NoLenBoomFile()) == 09798 def test_string(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 99why, one step back99 assert super_len("Test") == 4Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 100–101why, one step back100101 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 102–107why, one step back102 "mode, warnings_num",103 (104 ("r", 1),105 ("rb", 0),106 ),107 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 108why, one step back108 def test_file(self, tmpdir, mode, warnings_num, recwarn):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 109–110why, one step back109 file_obj = tmpdir.join("test.txt")110 file_obj.write("Test")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 111–113why, one step back111 with file_obj.open(mode) as fd:112 assert super_len(fd) == 4113 assert len(recwarn) == warnings_numCatch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
lines 114–115why, one step back114115 def test_tarfile_member(self, tmpdir):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 116–117why, one step back116 file_obj = tmpdir.join("test.txt")117 file_obj.write("Test")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 118why, one step back118Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 119–121why, one step back119 tar_obj = str(tmpdir.join("test.tar"))120 with tarfile.open(tar_obj, "w") as tar:121 tar.add(str(file_obj), arcname="test.txt")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
lines 122–123why, one step back122123 with tarfile.open(tar_obj) as tar:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 124why, one step back124 member = tar.extractfile("test.txt")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 125why, one step back125 assert super_len(member) == 4Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 126–127why, one step back126127 def test_super_len_with__len__(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 128why, one step back128 foo = [1, 2, 3, 4]Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 129–132why, one step back129 len_foo = super_len(foo)130 assert len_foo == 4131132 def test_super_len_with_no__len__(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 133why, one step back133 class LenFile:Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 134–139why, one step back134 def __init__(self):135 self.len = 5136137 assert super_len(LenFile()) == 5138139 def test_super_len_with_tell(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 140why, one step back140 foo = StringIO.StringIO("12345")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 141–145why, one step back141 assert super_len(foo) == 5142 foo.read(2)143 assert super_len(foo) == 3144145 def test_super_len_with_fileno(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 146why, one step back146 with open(__file__, "rb") as f:Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 147–153why, one step back147 length = super_len(f)148 file_data = f.read()149 assert length == len(file_data)150151 def test_super_len_with_no_matches(self):152 """Ensure that objects without any length methods default to 0"""153 assert super_len(object()) == 0Add more tests to prevent regression of CVE 2024 47081Arthur Woimbéebefore adoption5b4b64c
lines 154–171why, one step back154155156class TestGetNetrcAuth:157 def test_works(self, tmp_path, monkeypatch):158 netrc_path = tmp_path / ".netrc"159 monkeypatch.setenv("NETRC", str(netrc_path))160 with open(netrc_path, "w") as f:161 f.write("machine example.com login aaaa password bbbb\n")162 auth = get_netrc_auth("http://example.com/thing")163 assert auth == ("aaaa", "bbbb")164165 def test_not_vulnerable_to_bad_url_parsing(self, tmp_path, monkeypatch):166 netrc_path = tmp_path / ".netrc"167 monkeypatch.setenv("NETRC", str(netrc_path))168 with open(netrc_path, "w") as f:169 f.write("machine example.com login aaaa password bbbb\n")170 auth = get_netrc_auth("http://example.com:@evil.com/'")171 assert auth is NoneTime out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 172–175why, one step back172173174class TestToKeyValList:175 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 176–183why, one step back176 "value, expected",177 (178 ([("key", "val")], [("key", "val")]),179 ((("key", "val"),), [("key", "val")]),180 ({"key": "val"}, [("key", "val")]),181 (None, None),182 ),183 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 184–188why, one step back184 def test_valid(self, value, expected):185 assert to_key_val_list(value) == expected186187 def test_invalid(self):188 with pytest.raises(ValueError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 189why, one step back189 to_key_val_list("string")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 190–193why, one step back190191192class TestUnquoteHeaderValue:193 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 194–195why, one step back194 "value, expected",195 (Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 196why, one step back196 (None, None),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 197–202why, one step back197 ("Test", "Test"),198 ('"Test"', "Test"),199 ('"Test\\\\"', "Test\\"),200 ('"\\\\Comp\\Res"', "\\Comp\\Res"),201 ),202 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 203–206why, one step back203 def test_valid(self, value, expected):204 assert unquote_header_value(value) == expected205206 def test_is_filename(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 207why, one step back207 assert unquote_header_value('"\\\\Comp\\Res"', True) == "\\\\Comp\\Res"Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 208–214why, one step back208209210class TestGetEnvironProxies:211 """Ensures that IP addresses are correctly matches with ranges212 in no_proxy variable.213 """214Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 215why, one step back215 @pytest.fixture(autouse=True, params=["no_proxy", "NO_PROXY"])Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 216why, one step back216 def no_proxy(self, request, monkeypatch):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 217–219why, one step back217 monkeypatch.setenv(218 request.param, "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"219 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 220–221why, one step back220221 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 222–230why, one step back222 "url",223 (224 "http://192.168.0.1:5000/",225 "http://192.168.0.1/",226 "http://172.16.1.1/",227 "http://172.16.1.1:5000/",228 "http://localhost.localdomain:5000/v1.0/",229 ),230 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 231–234why, one step back231 def test_bypass(self, url):232 assert get_environ_proxies(url, no_proxy=None) == {}233234 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 235–241why, one step back235 "url",236 (237 "http://192.168.1.1:5000/",238 "http://192.168.1.1/",239 "http://www.requests.com/",240 ),241 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 242–245why, one step back242 def test_not_bypass(self, url):243 assert get_environ_proxies(url, no_proxy=None) != {}244245 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 246–252why, one step back246 "url",247 (248 "http://192.168.1.1:5000/",249 "http://192.168.1.1/",250 "http://www.requests.com/",251 ),252 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 253why, one step back253 def test_bypass_no_proxy_keyword(self, url):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 254why, one step back254 no_proxy = "192.168.1.1,requests.com"Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 255–257why, one step back255 assert get_environ_proxies(url, no_proxy=no_proxy) == {}256257 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 258–266why, one step back258 "url",259 (260 "http://192.168.0.1:5000/",261 "http://192.168.0.1/",262 "http://172.16.1.1/",263 "http://172.16.1.1:5000/",264 "http://localhost.localdomain:5000/v1.0/",265 ),266 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 267–269why, one step back267 def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):268 # This is testing that the 'no_proxy' argument overrides the269 # environment variable 'no_proxy'Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 270–271why, one step back270 monkeypatch.setenv("http_proxy", "http://proxy.example.com:3128/")271 no_proxy = "192.168.1.1,requests.com"Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 272–276why, one step back272 assert get_environ_proxies(url, no_proxy=no_proxy) != {}273274275class TestIsIPv4Address:276 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 277why, one step back277 assert is_ipv4_address("8.8.8.8")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 278why, one step back278Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 279why, one step back279 @pytest.mark.parametrize("value", ("8.8.8.8.8", "localhost.localdomain"))Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 280–285why, one step back280 def test_invalid(self, value):281 assert not is_ipv4_address(value)282283284class TestIsValidCIDR:285 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 286why, one step back286 assert is_valid_cidr("192.168.1.0/24")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 287–288why, one step back287288 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 289–297why, one step back289 "value",290 (291 "8.8.8.8",292 "192.168.1.0/a",293 "192.168.1.0/128",294 "192.168.1.0/-1",295 "192.168.1.999/24",296 ),297 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 298–303why, one step back298 def test_invalid(self, value):299 assert not is_valid_cidr(value)300301302class TestAddressInNetwork:303 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 304why, one step back304 assert address_in_network("192.168.1.1", "192.168.1.0/24")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 305–306why, one step back305306 def test_invalid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 307why, one step back307 assert not address_in_network("172.16.0.1", "192.168.1.0/24")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 308–311why, one step back308309310class TestGuessFilename:311 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 312–313why, one step back312 "value",313 (1, type("Fake", (object,), {"name": 1})()),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 314–318why, one step back314 )315 def test_guess_filename_invalid(self, value):316 assert guess_filename(value) is None317318 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 319–324why, one step back319 "value, expected_type",320 (321 (b"value", compat.bytes),322 (b"value".decode("utf-8"), compat.str),323 ),324 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 325why, one step back325 def test_guess_filename_valid(self, value, expected_type):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 326why, one step back326 obj = type("Fake", (object,), {"name": value})()Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 327–333why, one step back327 result = guess_filename(obj)328 assert result == value329 assert isinstance(result, expected_type)330331332class TestExtractZippedPaths:333 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 334–336why, one step back334 "path",335 (336 "/",Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 337–338why, one step back337 __file__,338 pytest.__file__,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 339–341why, one step back339 "/etc/invalid/location",340 ),341 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 342–345why, one step back342 def test_unzipped_paths_unchanged(self, path):343 assert path == extract_zipped_paths(path)344345 def test_zipped_paths_extracted(self, tmpdir):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 346–347why, one step back346 zipped_py = tmpdir.join("test.zip")347 with zipfile.ZipFile(zipped_py.strpath, "w") as f:Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 348–350why, one step back348 f.write(__file__)349350 _, name = os.path.splitdrive(__file__)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 351why, one step back351 zipped_path = os.path.join(zipped_py.strpath, name.lstrip(r"\/"))Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 352–364why, one step back352 extracted_path = extract_zipped_paths(zipped_path)353354 assert extracted_path != zipped_path355 assert os.path.exists(extracted_path)356 assert filecmp.cmp(extracted_path, __file__)357358 def test_invalid_unc_path(self):359 path = r"\\localhost\invalid\location"360 assert extract_zipped_paths(path) == path361362363class TestContentEncodingDetection:364 def test_none(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 365why, one step back365 encodings = get_encodings_from_content("")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 366–368why, one step back366 assert not len(encodings)367368 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 369–370why, one step back369 "content",370 (Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 371–378why, one step back371 # HTML5 meta charset attribute372 '<meta charset="UTF-8">',373 # HTML4 pragma directive374 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',375 # XHTML 1.x served with text/html MIME type376 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',377 # XHTML 1.x served as XML378 '<?xml version="1.0" encoding="UTF-8"?>',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 379–380why, one step back379 ),380 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 381–383why, one step back381 def test_pragmas(self, content):382 encodings = get_encodings_from_content(content)383 assert len(encodings) == 1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 384why, one step back384 assert encodings[0] == "UTF-8"Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 385–386why, one step back385386 def test_precedence(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 387why, one step back387 content = """Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 388–390why, one step back388 <?xml version="1.0" encoding="XML"?>389 <meta charset="HTML5">390 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 391–392why, one step back391 """.strip()392 assert get_encodings_from_content(content) == ["HTML5", "HTML4", "XML"]Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 393–396why, one step back393394395class TestGuessJSONUTF:396 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 397–408why, one step back397 "encoding",398 (399 "utf-32",400 "utf-8-sig",401 "utf-16",402 "utf-8",403 "utf-16-be",404 "utf-16-le",405 "utf-32-be",406 "utf-32-le",407 ),408 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 409why, one step back409 def test_encoded(self, encoding):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 410why, one step back410 data = "{}".encode(encoding)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 411–413why, one step back411 assert guess_json_utf(data) == encoding412413 def test_bad_utf_like_encoding(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 414why, one step back414 assert guess_json_utf(b"\x00\x00\x00\x00") is NoneTime out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 415–416why, one step back415416 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 417–424why, one step back417 ("encoding", "expected"),418 (419 ("utf-16-be", "utf-16"),420 ("utf-16-le", "utf-16"),421 ("utf-32-be", "utf-32"),422 ("utf-32-le", "utf-32"),423 ),424 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 425why, one step back425 def test_guess_by_bom(self, encoding, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 426why, one step back426 data = "\ufeff{}".encode(encoding)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 427–430why, one step back427 assert guess_json_utf(data) == expected428429430USER = PASSWORD = "%!*'();:@&=+$,/?#[] "Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 431–432why, one step back431ENCODED_USER = compat.quote(USER, "")432ENCODED_PASSWORD = compat.quote(PASSWORD, "")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 433–435why, one step back433434435@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 436–437why, one step back436 "url, auth",437 (Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 438why, one step back438 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 439–440why, one step back439 f"http://{ENCODED_USER}:{ENCODED_PASSWORD}@request.com/url.html#test",440 (USER, PASSWORD),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 441why, one step back441 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 442why, one step back442 ("http://user:pass@complex.url.com/path?query=yes", ("user", "pass")),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 443why, one step back443 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 444–445why, one step back444 "http://user:pass%20pass@complex.url.com/path?query=yes",445 ("user", "pass pass"),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 446why, one step back446 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 447why, one step back447 ("http://user:pass pass@complex.url.com/path?query=yes", ("user", "pass pass")),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 448why, one step back448 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 449–450why, one step back449 "http://user%25user:pass@complex.url.com/path?query=yes",450 ("user%user", "pass"),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 451–452why, one step back451 ),452 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 453–454why, one step back453 "http://user:pass%23pass@complex.url.com/path?query=yes",454 ("user", "pass#pass"),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 455why, one step back455 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 456–458why, one step back456 ("http://complex.url.com/path?query=yes", ("", "")),457 ),458)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 459–463why, one step back459def test_get_auth_from_url(url, auth):460 assert get_auth_from_url(url) == auth461462463@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 464–465why, one step back464 "uri, expected",465 (Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 466–467why, one step back466 (467 # Ensure requoting doesn't break expectationsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 468–469why, one step back468 "http://example.com/fiz?buz=%25ppicture",469 "http://example.com/fiz?buz=%25ppicture",Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 470–472why, one step back470 ),471 (472 # Ensure we handle unquoted percent signs in redirectsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 473–474why, one step back473 "http://example.com/fiz?buz=%ppicture",474 "http://example.com/fiz?buz=%25ppicture",Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 475why, one step back475 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 476–477why, one step back476 ),477)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 478–483why, one step back478def test_requote_uri_with_unquoted_percents(uri, expected):479 """See: https://github.com/psf/requests/issues/2356"""480 assert requote_uri(uri) == expected481482483@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 484–485why, one step back484 "uri, expected",485 (Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 486–487why, one step back486 (487 # Illegal bytesAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 488–489why, one step back488 "http://example.com/?a=%--",489 "http://example.com/?a=%--",Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 490–492why, one step back490 ),491 (492 # Reserved charactersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 493–497why, one step back493 "http://example.com/?a=%300",494 "http://example.com/?a=00",495 ),496 ),497)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 498–502why, one step back498def test_unquote_unreserved(uri, expected):499 assert unquote_unreserved(uri) == expected500501502@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 503–509why, one step back503 "mask, expected",504 (505 (8, "255.0.0.0"),506 (24, "255.255.255.0"),507 (25, "255.255.255.128"),508 ),509)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 510–513why, one step back510def test_dotted_netmask(mask, expected):511 assert dotted_netmask(mask) == expected512513Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 514–526why, one step back514http_proxies = {515 "http": "http://http.proxy",516 "http://some.host": "http://some.host.proxy",517}518all_proxies = {519 "all": "socks5://http.proxy",520 "all://some.host": "socks5://some.host.proxy",521}522mixed_proxies = {523 "http": "http://http.proxy",524 "http://some.host": "http://some.host.proxy",525 "all": "socks5://http.proxy",526}Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 527–528why, one step back527528Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 529–545why, one step back529@pytest.mark.parametrize(530 "url, expected, proxies",531 (532 ("hTTp://u:p@Some.Host/path", "http://some.host.proxy", http_proxies),533 ("hTTp://u:p@Other.Host/path", "http://http.proxy", http_proxies),534 ("hTTp:///path", "http://http.proxy", http_proxies),535 ("hTTps://Other.Host", None, http_proxies),536 ("file:///etc/motd", None, http_proxies),537 ("hTTp://u:p@Some.Host/path", "socks5://some.host.proxy", all_proxies),538 ("hTTp://u:p@Other.Host/path", "socks5://http.proxy", all_proxies),539 ("hTTp:///path", "socks5://http.proxy", all_proxies),540 ("hTTps://Other.Host", "socks5://http.proxy", all_proxies),541 ("http://u:p@other.host/path", "http://http.proxy", mixed_proxies),542 ("http://u:p@some.host/path", "http://some.host.proxy", mixed_proxies),543 ("https://u:p@other.host/path", "socks5://http.proxy", mixed_proxies),544 ("https://u:p@some.host/path", "socks5://http.proxy", mixed_proxies),545 ("https://", "socks5://http.proxy", mixed_proxies),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 546why, one step back546 # XXX: unsure whether this is reasonable behaviorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 547–549why, one step back547 ("file:///etc/motd", "socks5://http.proxy", all_proxies),548 ),549)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 550–555why, one step back550def test_select_proxies(url, expected, proxies):551 """Make sure we can select per-host proxies correctly."""552 assert select_proxy(url, proxies) == expected553554555@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 556–561why, one step back556 "value, expected",557 (558 ('foo="is a fish", bar="as well"', {"foo": "is a fish", "bar": "as well"}),559 ("key_without_value", {"key_without_value": None}),560 ),561)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 562–566why, one step back562def test_parse_dict_header(value, expected):563 assert parse_dict_header(value) == expected564565566@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 567–569why, one step back567 "value, expected",568 (569 ("application/xml", ("application/xml", {})),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 570why, one step back570 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 571–572why, one step back571 "application/json ; charset=utf-8",572 ("application/json", {"charset": "utf-8"}),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 573–574why, one step back573 ),574 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 575–576why, one step back575 "application/json ; Charset=utf-8",576 ("application/json", {"charset": "utf-8"}),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 577why, one step back577 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 578why, one step back578 ("text/plain", ("text/plain", {})),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 579why, one step back579 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 580–588why, one step back580 "multipart/form-data; boundary = something ; boundary2='something_else' ; no_equals ",581 (582 "multipart/form-data",583 {584 "boundary": "something",585 "boundary2": "something_else",586 "no_equals": True,587 },588 ),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 589–590why, one step back589 ),590 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 591–599why, one step back591 'multipart/form-data; boundary = something ; boundary2="something_else" ; no_equals ',592 (593 "multipart/form-data",594 {595 "boundary": "something",596 "boundary2": "something_else",597 "no_equals": True,598 },599 ),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 600–601why, one step back600 ),601 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 602–610why, one step back602 "multipart/form-data; boundary = something ; 'boundary2=something_else' ; no_equals ",603 (604 "multipart/form-data",605 {606 "boundary": "something",607 "boundary2": "something_else",608 "no_equals": True,609 },610 ),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 611–613why, one step back611 ),612 (613 'multipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals ',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 614–621why, one step back614 (615 "multipart/form-data",616 {617 "boundary": "something",618 "boundary2": "something_else",619 "no_equals": True,620 },621 ),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 622why, one step back622 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 623–625why, one step back623 ("application/json ; ; ", ("application/json", {})),624 ),625)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 626–630why, one step back626def test__parse_content_type_header(value, expected):627 assert _parse_content_type_header(value) == expected628629630@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 631–633why, one step back631 "value, expected",632 (633 (CaseInsensitiveDict(), None),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 634why, one step back634 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 635–636why, one step back635 CaseInsensitiveDict({"content-type": "application/json; charset=utf-8"}),636 "utf-8",Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 637why, one step back637 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 638–640why, one step back638 (CaseInsensitiveDict({"content-type": "text/plain"}), "ISO-8859-1"),639 ),640)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 641–645why, one step back641def test_get_encoding_from_headers(value, expected):642 assert get_encoding_from_headers(value) == expected643644645@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 646–655why, one step back646 "value, length",647 (648 ("", 0),649 ("T", 1),650 ("Test", 4),651 ("Cont", 0),652 ("Other", -5),653 ("Content", None),654 ),655)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 656–664why, one step back656def test_iter_slices(value, length):657 if length is None or (length <= 0 and len(value) > 0):658 # Reads all content at once659 assert len(list(iter_slices(value, length))) == 1660 else:661 assert len(list(iter_slices(value, 1))) == length662663664@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 665–666why, one step back665 "value, expected",666 (Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 667–668why, one step back667 (668 '<http:/.../front.jpeg>; rel=front; type="image/jpeg"',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 669why, one step back669 [{"url": "http:/.../front.jpeg", "rel": "front", "type": "image/jpeg"}],Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 670why, one step back670 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 671–672why, one step back671 ("<http:/.../front.jpeg>", [{"url": "http:/.../front.jpeg"}]),672 ("<http:/.../front.jpeg>;", [{"url": "http:/.../front.jpeg"}]),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 673–675why, one step back673 (674 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',675 [Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 676–678why, one step back676 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},677 {"url": "http://.../back.jpeg"},678 ],Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 679why, one step back679 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 680–682why, one step back680 ("", []),681 ),682)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 683–687why, one step back683def test_parse_header_links(value, expected):684 assert parse_header_links(value) == expected685686687@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 688–692why, one step back688 "value, expected",689 (690 ("example.com/path", "http://example.com/path"),691 ("//example.com/path", "http://example.com/path"),692 ("example.com:80", "http://example.com:80"),Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724
line 693why, one step back693 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 694–695why, one step back694 "http://user:pass@example.com/path?query",695 "http://user:pass@example.com/path?query",Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724
line 696why, one step back696 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 697–699why, one step back697 ("http://user@example.com/path?query", "http://user@example.com/path?query"),698 ),699)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 700why, one step back700def test_prepend_scheme_if_needed(value, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 701why, one step back701 assert prepend_scheme_if_needed(value, "http") == expectedTime out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 702–704why, one step back702703704@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 705–711why, one step back705 "value, expected",706 (707 ("T", "T"),708 (b"T", "T"),709 ("T", "T"),710 ),711)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 712–716why, one step back712def test_to_native_string(value, expected):713 assert to_native_string(value) == expected714715716@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 717–726why, one step back717 "url, expected",718 (719 ("http://u:p@example.com/path?a=1#test", "http://example.com/path?a=1"),720 ("http://example.com/path", "http://example.com/path"),721 ("//u:p@example.com/path", "//example.com/path"),722 ("//example.com/path", "//example.com/path"),723 ("example.com/path", "//example.com/path"),724 ("scheme:u:p@example.com/path", "scheme://example.com/path"),725 ),726)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 727–731why, one step back727def test_urldefragauth(url, expected):728 assert urldefragauth(url) == expected729730731@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 732–745why, one step back732 "url, expected",733 (734 ("http://192.168.0.1:5000/", True),735 ("http://192.168.0.1/", True),736 ("http://172.16.1.1/", True),737 ("http://172.16.1.1:5000/", True),738 ("http://localhost.localdomain:5000/v1.0/", True),739 ("http://google.com:6000/", True),740 ("http://172.16.1.12/", False),741 ("http://172.16.1.12:5000/", False),742 ("http://google.com:5000/v1.0/", False),743 ("file:///some/path/on/disk", True),744 ),745)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 746–749why, one step back746def test_should_bypass_proxies(url, expected, monkeypatch):747 """Tests for function should_bypass_proxies to check if proxy748 can be bypassed or not749 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 750–757why, one step back750 monkeypatch.setenv(751 "no_proxy",752 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",753 )754 monkeypatch.setenv(755 "NO_PROXY",756 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",757 )Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 758–761why, one step back758 assert should_bypass_proxies(url, no_proxy=None) == expected759760761@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 762–773why, one step back762 "url, expected",763 (764 ("http://172.16.1.1/", "172.16.1.1"),765 ("http://172.16.1.1:5000/", "172.16.1.1"),766 ("http://user:pass@172.16.1.1", "172.16.1.1"),767 ("http://user:pass@172.16.1.1:5000", "172.16.1.1"),768 ("http://hostname/", "hostname"),769 ("http://hostname:5000/", "hostname"),770 ("http://user:pass@hostname", "hostname"),771 ("http://user:pass@hostname:5000", "hostname"),772 ),773)Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 774why, one step back774def test_should_bypass_proxies_pass_only_hostname(url, expected):Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 775–777why, one step back775 """The proxy_bypass function should be called with a hostname or IP without776 a port number or auth credentials.777 """Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
lines 778–780why, one step back778 with mock.patch("requests.utils.proxy_bypass") as proxy_bypass:779 should_bypass_proxies(url, no_proxy=None)780 proxy_bypass.assert_called_once_with(expected)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 781–783why, one step back781782783@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 784–785why, one step back784 "cookiejar",785 (Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 786why, one step back786 compat.cookielib.CookieJar(),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 787–789why, one step back787 RequestsCookieJar(),788 ),789)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 790–793why, one step back790def test_add_dict_to_cookiejar(cookiejar):791 """Ensure add_dict_to_cookiejar works for792 non-RequestsCookieJar CookieJars793 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 794why, one step back794 cookiedict = {"test": "cookies", "good": "cookies"}Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 795–800why, one step back795 cj = add_dict_to_cookiejar(cookiejar, cookiedict)796 cookies = {cookie.name: cookie.value for cookie in cj}797 assert cookiedict == cookies798799800@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 801–806why, one step back801 "value, expected",802 (803 ("test", True),804 ("æíöû", False),805 ("ジェーピーニック", False),806 ),Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 807–812why, one step back807)808def test_unicode_is_ascii(value, expected):809 assert unicode_is_ascii(value) is expected810811812@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 813–825why, one step back813 "url, expected",814 (815 ("http://192.168.0.1:5000/", True),816 ("http://192.168.0.1/", True),817 ("http://172.16.1.1/", True),818 ("http://172.16.1.1:5000/", True),819 ("http://localhost.localdomain:5000/v1.0/", True),820 ("http://172.16.1.12/", False),821 ("http://172.16.1.12:5000/", False),822 ("http://google.com:5000/v1.0/", False),823 ),824)825def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 826–828why, one step back826 """Tests for function should_bypass_proxies to check if proxy827 can be bypassed or not using the 'no_proxy' argument828 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 829why, one step back829 no_proxy = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 830–833why, one step back830 # Test 'no_proxy' argument831 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected832833Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 834why, one step back834@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 835why, one step back835@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 836–850why, one step back836 "url, expected, override",837 (838 ("http://192.168.0.1:5000/", True, None),839 ("http://192.168.0.1/", True, None),840 ("http://172.16.1.1/", True, None),841 ("http://172.16.1.1:5000/", True, None),842 ("http://localhost.localdomain:5000/v1.0/", True, None),843 ("http://172.16.1.22/", False, None),844 ("http://172.16.1.22:5000/", False, None),845 ("http://google.com:5000/v1.0/", False, None),846 ("http://mylocalhostname:5000/v1.0/", True, "<local>"),847 ("http://192.168.0.1/", False, ""),848 ),849)850def test_should_bypass_proxies_win_registry(url, expected, override, monkeypatch):Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 851–854why, one step back851 """Tests for function should_bypass_proxies to check if proxy852 can be bypassed or not with Windows registry settings853 """854 if override is None:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 855why, one step back855 override = "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583
line 856why, one step back856 import winregTime out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 857–869why, one step back857858 class RegHandle:859 def Close(self):860 pass861862 ie_settings = RegHandle()863 proxyEnableValues = deque([1, "1"])864865 def OpenKey(key, subkey):866 return ie_settings867868 def QueryValueEx(key, value_name):869 if key is ie_settings:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 870why, one step back870 if value_name == "ProxyEnable":Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 871–873why, one step back871 # this could be a string (REG_SZ) or a 32-bit number (REG_DWORD)872 proxyEnableValues.rotate()873 return [proxyEnableValues[0]]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 874why, one step back874 elif value_name == "ProxyOverride":Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 875–876why, one step back875 return [override]876Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 877–883why, one step back877 monkeypatch.setenv("http_proxy", "")878 monkeypatch.setenv("https_proxy", "")879 monkeypatch.setenv("ftp_proxy", "")880 monkeypatch.setenv("no_proxy", "")881 monkeypatch.setenv("NO_PROXY", "")882 monkeypatch.setattr(winreg, "OpenKey", OpenKey)883 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 884–886why, one step back884 assert should_bypass_proxies(url, None) == expected885886Tolerate bad registry entries in Windows proxy settings (#6149)Nate Prewittbefore adoption210095f
lines 887–919why, one step back887@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")888def test_should_bypass_proxies_win_registry_bad_values(monkeypatch):889 """Tests for function should_bypass_proxies to check if proxy890 can be bypassed or not with Windows invalid registry settings.891 """892 import winreg893894 class RegHandle:895 def Close(self):896 pass897898 ie_settings = RegHandle()899900 def OpenKey(key, subkey):901 return ie_settings902903 def QueryValueEx(key, value_name):904 if key is ie_settings:905 if value_name == "ProxyEnable":906 # Invalid response; Should be an int or int-y value907 return [""]908 elif value_name == "ProxyOverride":909 return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"]910911 monkeypatch.setenv("http_proxy", "")912 monkeypatch.setenv("https_proxy", "")913 monkeypatch.setenv("no_proxy", "")914 monkeypatch.setenv("NO_PROXY", "")915 monkeypatch.setattr(winreg, "OpenKey", OpenKey)916 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)917 assert should_bypass_proxies("http://172.16.1.1/", None) is False918919Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 920why, one step back920@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 921–928why, one step back921 "env_name, value",922 (923 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),924 ("no_proxy", None),925 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),926 ("a_new_key", None),927 ),928)Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
lines 929–941why, one step back929def test_set_environ(env_name, value):930 """Tests set_environ will set environ values and will restore the environ."""931 environ_copy = copy.deepcopy(os.environ)932 with set_environ(env_name, value):933 assert os.environ.get(env_name) == value934935 assert os.environ == environ_copy936937938def test_set_environ_raises_exception():939 """Tests set_environ will raise exceptions in context when the940 value parameter is None."""941 with pytest.raises(Exception) as exception:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 942–943why, one step back942 with set_environ("test1", None):943 raise Exception("Expected exception")Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801
line 944why, one step back944Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 945why, one step back945 assert "Expected exception" in str(exception.value)Merge pull request #6302 from flysee/mainIan Stapleton Cordascobefore adoption8dd3b26
lines 946–977why, one step back946947948@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")949def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):950 """Tests for function should_bypass_proxies to check if proxy951 can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.952 """953 import winreg954955 class RegHandle:956 def Close(self):957 pass958959 ie_settings = RegHandle()960961 def OpenKey(key, subkey):962 return ie_settings963964 def QueryValueEx(key, value_name):965 if key is ie_settings:966 if value_name == "ProxyEnable":967 return [1]968 elif value_name == "ProxyOverride":969 return [970 "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"971 ]972973 monkeypatch.setenv("NO_PROXY", "")974 monkeypatch.setenv("no_proxy", "")975 monkeypatch.setattr(winreg, "OpenKey", OpenKey)976 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)977 assert should_bypass_proxies("http://example.com/", None) is False