test_utils.py
This file
Path
tests/test_utils.py
987 lines · 29.9 KiB · Python
Last changed by
Fix empty netrc entry usage (#7205)Nate Prewittbefore adoption4791422
History of this fileTake it
The walk stopped after 200 commits: lines older than 24dfbfd point at it.
Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 1–2why, one step back1import copy2import filecmpAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 3why, one step back3import osUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 4–6why, one step back4import tarfile5import 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 mockUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 9–10why, one step back910import pytestAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 11why, one step back11Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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_asciiUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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])Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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])Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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") == 4Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 111–115why, one step back111 with file_obj.open(mode) as fd:112 assert super_len(fd) == 4113 assert len(recwarn) == warnings_num114115 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")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 125–127why, one step back125 assert super_len(member) == 4126127 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]Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
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 NoneUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 172why, one step back172Fix empty netrc entry usage (#7205)Nate Prewittbefore adoption4791422
lines 173–182why, one step back173 def test_empty_default_credentials_ignored(self, tmp_path, monkeypatch):174 """Empty default credentials should not be returned."""175 netrc_path = tmp_path / ".netrc"176 monkeypatch.setenv("NETRC", str(netrc_path))177 with open(netrc_path, "w") as f:178 f.write("machine example.com login user password pass\ndefault\n")179180 auth = get_netrc_auth("http://httpbin.org/")181 assert auth is None182Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 183–185why, one step back183184class TestToKeyValList:185 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 186–193why, one step back186 "value, expected",187 (188 ([("key", "val")], [("key", "val")]),189 ((("key", "val"),), [("key", "val")]),190 ({"key": "val"}, [("key", "val")]),191 (None, None),192 ),193 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 194–198why, one step back194 def test_valid(self, value, expected):195 assert to_key_val_list(value) == expected196197 def test_invalid(self):198 with pytest.raises(ValueError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 199why, one step back199 to_key_val_list("string")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 200–203why, one step back200201202class TestUnquoteHeaderValue:203 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 204–205why, one step back204 "value, expected",205 (Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 206why, one step back206 (None, None),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 207–212why, one step back207 ("Test", "Test"),208 ('"Test"', "Test"),209 ('"Test\\\\"', "Test\\"),210 ('"\\\\Comp\\Res"', "\\Comp\\Res"),211 ),212 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 213–216why, one step back213 def test_valid(self, value, expected):214 assert unquote_header_value(value) == expected215216 def test_is_filename(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 217why, one step back217 assert unquote_header_value('"\\\\Comp\\Res"', True) == "\\\\Comp\\Res"Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 218–224why, one step back218219220class TestGetEnvironProxies:221 """Ensures that IP addresses are correctly matches with ranges222 in no_proxy variable.223 """224Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 225why, one step back225 @pytest.fixture(autouse=True, params=["no_proxy", "NO_PROXY"])Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 226why, one step back226 def no_proxy(self, request, monkeypatch):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 227–229why, one step back227 monkeypatch.setenv(228 request.param, "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"229 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 230–231why, one step back230231 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 232–240why, one step back232 "url",233 (234 "http://192.168.0.1:5000/",235 "http://192.168.0.1/",236 "http://172.16.1.1/",237 "http://172.16.1.1:5000/",238 "http://localhost.localdomain:5000/v1.0/",239 ),240 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 241–244why, one step back241 def test_bypass(self, url):242 assert get_environ_proxies(url, no_proxy=None) == {}243244 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 245–251why, one step back245 "url",246 (247 "http://192.168.1.1:5000/",248 "http://192.168.1.1/",249 "http://www.requests.com/",250 ),251 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 252–255why, one step back252 def test_not_bypass(self, url):253 assert get_environ_proxies(url, no_proxy=None) != {}254255 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 256–262why, one step back256 "url",257 (258 "http://192.168.1.1:5000/",259 "http://192.168.1.1/",260 "http://www.requests.com/",261 ),262 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 263why, one step back263 def test_bypass_no_proxy_keyword(self, url):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 264why, one step back264 no_proxy = "192.168.1.1,requests.com"Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 265–267why, one step back265 assert get_environ_proxies(url, no_proxy=no_proxy) == {}266267 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 268–276why, one step back268 "url",269 (270 "http://192.168.0.1:5000/",271 "http://192.168.0.1/",272 "http://172.16.1.1/",273 "http://172.16.1.1:5000/",274 "http://localhost.localdomain:5000/v1.0/",275 ),276 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 277–279why, one step back277 def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):278 # This is testing that the 'no_proxy' argument overrides the279 # environment variable 'no_proxy'Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 280–281why, one step back280 monkeypatch.setenv("http_proxy", "http://proxy.example.com:3128/")281 no_proxy = "192.168.1.1,requests.com"Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 282–286why, one step back282 assert get_environ_proxies(url, no_proxy=no_proxy) != {}283284285class TestIsIPv4Address:286 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 287why, one step back287 assert is_ipv4_address("8.8.8.8")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 288why, one step back288Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 289why, one step back289 @pytest.mark.parametrize("value", ("8.8.8.8.8", "localhost.localdomain"))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 290–295why, one step back290 def test_invalid(self, value):291 assert not is_ipv4_address(value)292293294class TestIsValidCIDR:295 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 296why, one step back296 assert is_valid_cidr("192.168.1.0/24")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 297–298why, one step back297298 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 299–307why, one step back299 "value",300 (301 "8.8.8.8",302 "192.168.1.0/a",303 "192.168.1.0/128",304 "192.168.1.0/-1",305 "192.168.1.999/24",306 ),307 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 308–313why, one step back308 def test_invalid(self, value):309 assert not is_valid_cidr(value)310311312class TestAddressInNetwork:313 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 314why, one step back314 assert address_in_network("192.168.1.1", "192.168.1.0/24")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 315–316why, one step back315316 def test_invalid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 317why, one step back317 assert not address_in_network("172.16.0.1", "192.168.1.0/24")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 318–321why, one step back318319320class TestGuessFilename:321 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 322–323why, one step back322 "value",323 (1, type("Fake", (object,), {"name": 1})()),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 324–328why, one step back324 )325 def test_guess_filename_invalid(self, value):326 assert guess_filename(value) is None327328 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 329–334why, one step back329 "value, expected_type",330 (331 (b"value", compat.bytes),332 (b"value".decode("utf-8"), compat.str),333 ),334 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 335why, one step back335 def test_guess_filename_valid(self, value, expected_type):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 336why, one step back336 obj = type("Fake", (object,), {"name": value})()Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 337–343why, one step back337 result = guess_filename(obj)338 assert result == value339 assert isinstance(result, expected_type)340341342class TestExtractZippedPaths:343 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 344–346why, one step back344 "path",345 (346 "/",Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 347–348why, one step back347 __file__,348 pytest.__file__,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 349–351why, one step back349 "/etc/invalid/location",350 ),351 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 352–355why, one step back352 def test_unzipped_paths_unchanged(self, path):353 assert path == extract_zipped_paths(path)354355 def test_zipped_paths_extracted(self, tmpdir):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 356–357why, one step back356 zipped_py = tmpdir.join("test.zip")357 with zipfile.ZipFile(zipped_py.strpath, "w") as f:Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 358–360why, one step back358 f.write(__file__)359360 _, name = os.path.splitdrive(__file__)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 361why, one step back361 zipped_path = os.path.join(zipped_py.strpath, name.lstrip(r"\/"))Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 362–374why, one step back362 extracted_path = extract_zipped_paths(zipped_path)363364 assert extracted_path != zipped_path365 assert os.path.exists(extracted_path)366 assert filecmp.cmp(extracted_path, __file__)367368 def test_invalid_unc_path(self):369 path = r"\\localhost\invalid\location"370 assert extract_zipped_paths(path) == path371372373class TestContentEncodingDetection:374 def test_none(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 375why, one step back375 encodings = get_encodings_from_content("")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 376–378why, one step back376 assert not len(encodings)377378 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 379–380why, one step back379 "content",380 (Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 381–388why, one step back381 # HTML5 meta charset attribute382 '<meta charset="UTF-8">',383 # HTML4 pragma directive384 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',385 # XHTML 1.x served with text/html MIME type386 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',387 # XHTML 1.x served as XML388 '<?xml version="1.0" encoding="UTF-8"?>',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 389–390why, one step back389 ),390 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 391–393why, one step back391 def test_pragmas(self, content):392 encodings = get_encodings_from_content(content)393 assert len(encodings) == 1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 394why, one step back394 assert encodings[0] == "UTF-8"Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 395–396why, one step back395396 def test_precedence(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 397why, one step back397 content = """Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 398–400why, one step back398 <?xml version="1.0" encoding="XML"?>399 <meta charset="HTML5">400 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 401–402why, one step back401 """.strip()402 assert get_encodings_from_content(content) == ["HTML5", "HTML4", "XML"]Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 403–406why, one step back403404405class TestGuessJSONUTF:406 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 407–418why, one step back407 "encoding",408 (409 "utf-32",410 "utf-8-sig",411 "utf-16",412 "utf-8",413 "utf-16-be",414 "utf-16-le",415 "utf-32-be",416 "utf-32-le",417 ),418 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 419why, one step back419 def test_encoded(self, encoding):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 420why, one step back420 data = "{}".encode(encoding)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 421–423why, one step back421 assert guess_json_utf(data) == encoding422423 def test_bad_utf_like_encoding(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 424why, one step back424 assert guess_json_utf(b"\x00\x00\x00\x00") is NoneUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 425–426why, one step back425426 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 427–434why, one step back427 ("encoding", "expected"),428 (429 ("utf-16-be", "utf-16"),430 ("utf-16-le", "utf-16"),431 ("utf-32-be", "utf-32"),432 ("utf-32-le", "utf-32"),433 ),434 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 435why, one step back435 def test_guess_by_bom(self, encoding, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 436why, one step back436 data = "\ufeff{}".encode(encoding)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 437–440why, one step back437 assert guess_json_utf(data) == expected438439440USER = PASSWORD = "%!*'();:@&=+$,/?#[] "Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 441–442why, one step back441ENCODED_USER = compat.quote(USER, "")442ENCODED_PASSWORD = compat.quote(PASSWORD, "")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 443–445why, one step back443444445@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 446–447why, one step back446 "url, auth",447 (Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 448why, one step back448 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 449–450why, one step back449 f"http://{ENCODED_USER}:{ENCODED_PASSWORD}@request.com/url.html#test",450 (USER, PASSWORD),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 451why, one step back451 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 452why, one step back452 ("http://user:pass@complex.url.com/path?query=yes", ("user", "pass")),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 453why, one step back453 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 454–455why, one step back454 "http://user:pass%20pass@complex.url.com/path?query=yes",455 ("user", "pass pass"),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 456why, one step back456 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 457why, one step back457 ("http://user:pass pass@complex.url.com/path?query=yes", ("user", "pass pass")),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 458why, one step back458 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 459–460why, one step back459 "http://user%25user:pass@complex.url.com/path?query=yes",460 ("user%user", "pass"),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 461–462why, one step back461 ),462 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 463–464why, one step back463 "http://user:pass%23pass@complex.url.com/path?query=yes",464 ("user", "pass#pass"),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 465why, one step back465 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 466–468why, one step back466 ("http://complex.url.com/path?query=yes", ("", "")),467 ),468)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 469–473why, one step back469def test_get_auth_from_url(url, auth):470 assert get_auth_from_url(url) == auth471472473@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 474–475why, one step back474 "uri, expected",475 (Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 476–477why, one step back476 (477 # Ensure requoting doesn't break expectationsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 478–479why, one step back478 "http://example.com/fiz?buz=%25ppicture",479 "http://example.com/fiz?buz=%25ppicture",Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 480–482why, one step back480 ),481 (482 # Ensure we handle unquoted percent signs in redirectsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 483–484why, one step back483 "http://example.com/fiz?buz=%ppicture",484 "http://example.com/fiz?buz=%25ppicture",Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 485why, one step back485 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 486–487why, one step back486 ),487)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 488–493why, one step back488def test_requote_uri_with_unquoted_percents(uri, expected):489 """See: https://github.com/psf/requests/issues/2356"""490 assert requote_uri(uri) == expected491492493@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 494–495why, one step back494 "uri, expected",495 (Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 496–497why, one step back496 (497 # Illegal bytesAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 498–499why, one step back498 "http://example.com/?a=%--",499 "http://example.com/?a=%--",Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 500–502why, one step back500 ),501 (502 # Reserved charactersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 503–507why, one step back503 "http://example.com/?a=%300",504 "http://example.com/?a=00",505 ),506 ),507)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 508–512why, one step back508def test_unquote_unreserved(uri, expected):509 assert unquote_unreserved(uri) == expected510511512@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 513–519why, one step back513 "mask, expected",514 (515 (8, "255.0.0.0"),516 (24, "255.255.255.0"),517 (25, "255.255.255.128"),518 ),519)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 520–523why, one step back520def test_dotted_netmask(mask, expected):521 assert dotted_netmask(mask) == expected522523Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 524–536why, one step back524http_proxies = {525 "http": "http://http.proxy",526 "http://some.host": "http://some.host.proxy",527}528all_proxies = {529 "all": "socks5://http.proxy",530 "all://some.host": "socks5://some.host.proxy",531}532mixed_proxies = {533 "http": "http://http.proxy",534 "http://some.host": "http://some.host.proxy",535 "all": "socks5://http.proxy",536}Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 537–538why, one step back537538Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 539–555why, one step back539@pytest.mark.parametrize(540 "url, expected, proxies",541 (542 ("hTTp://u:p@Some.Host/path", "http://some.host.proxy", http_proxies),543 ("hTTp://u:p@Other.Host/path", "http://http.proxy", http_proxies),544 ("hTTp:///path", "http://http.proxy", http_proxies),545 ("hTTps://Other.Host", None, http_proxies),546 ("file:///etc/motd", None, http_proxies),547 ("hTTp://u:p@Some.Host/path", "socks5://some.host.proxy", all_proxies),548 ("hTTp://u:p@Other.Host/path", "socks5://http.proxy", all_proxies),549 ("hTTp:///path", "socks5://http.proxy", all_proxies),550 ("hTTps://Other.Host", "socks5://http.proxy", all_proxies),551 ("http://u:p@other.host/path", "http://http.proxy", mixed_proxies),552 ("http://u:p@some.host/path", "http://some.host.proxy", mixed_proxies),553 ("https://u:p@other.host/path", "socks5://http.proxy", mixed_proxies),554 ("https://u:p@some.host/path", "socks5://http.proxy", mixed_proxies),555 ("https://", "socks5://http.proxy", mixed_proxies),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 556why, one step back556 # XXX: unsure whether this is reasonable behaviorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 557–559why, one step back557 ("file:///etc/motd", "socks5://http.proxy", all_proxies),558 ),559)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 560–565why, one step back560def test_select_proxies(url, expected, proxies):561 """Make sure we can select per-host proxies correctly."""562 assert select_proxy(url, proxies) == expected563564565@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 566–571why, one step back566 "value, expected",567 (568 ('foo="is a fish", bar="as well"', {"foo": "is a fish", "bar": "as well"}),569 ("key_without_value", {"key_without_value": None}),570 ),571)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 572–576why, one step back572def test_parse_dict_header(value, expected):573 assert parse_dict_header(value) == expected574575576@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 577–579why, one step back577 "value, expected",578 (579 ("application/xml", ("application/xml", {})),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 580why, one step back580 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 581–582why, one step back581 "application/json ; charset=utf-8",582 ("application/json", {"charset": "utf-8"}),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 583–584why, one step back583 ),584 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 585–586why, one step back585 "application/json ; Charset=utf-8",586 ("application/json", {"charset": "utf-8"}),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 587why, one step back587 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 588why, one step back588 ("text/plain", ("text/plain", {})),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 589why, one step back589 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 590–598why, one step back590 "multipart/form-data; boundary = something ; boundary2='something_else' ; no_equals ",591 (592 "multipart/form-data",593 {594 "boundary": "something",595 "boundary2": "something_else",596 "no_equals": True,597 },598 ),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 599–600why, one step back599 ),600 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 601–609why, one step back601 'multipart/form-data; boundary = something ; boundary2="something_else" ; no_equals ',602 (603 "multipart/form-data",604 {605 "boundary": "something",606 "boundary2": "something_else",607 "no_equals": True,608 },609 ),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 610–611why, one step back610 ),611 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 612–620why, one step back612 "multipart/form-data; boundary = something ; 'boundary2=something_else' ; no_equals ",613 (614 "multipart/form-data",615 {616 "boundary": "something",617 "boundary2": "something_else",618 "no_equals": True,619 },620 ),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 621–623why, one step back621 ),622 (623 'multipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals ',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 624–631why, one step back624 (625 "multipart/form-data",626 {627 "boundary": "something",628 "boundary2": "something_else",629 "no_equals": True,630 },631 ),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 632why, one step back632 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 633–635why, one step back633 ("application/json ; ; ", ("application/json", {})),634 ),635)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 636–640why, one step back636def test__parse_content_type_header(value, expected):637 assert _parse_content_type_header(value) == expected638639640@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 641–643why, one step back641 "value, expected",642 (643 (CaseInsensitiveDict(), None),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 644why, one step back644 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 645–646why, one step back645 CaseInsensitiveDict({"content-type": "application/json; charset=utf-8"}),646 "utf-8",Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 647why, one step back647 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 648–650why, one step back648 (CaseInsensitiveDict({"content-type": "text/plain"}), "ISO-8859-1"),649 ),650)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 651–655why, one step back651def test_get_encoding_from_headers(value, expected):652 assert get_encoding_from_headers(value) == expected653654655@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 656–665why, one step back656 "value, length",657 (658 ("", 0),659 ("T", 1),660 ("Test", 4),661 ("Cont", 0),662 ("Other", -5),663 ("Content", None),664 ),665)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 666–674why, one step back666def test_iter_slices(value, length):667 if length is None or (length <= 0 and len(value) > 0):668 # Reads all content at once669 assert len(list(iter_slices(value, length))) == 1670 else:671 assert len(list(iter_slices(value, 1))) == length672673674@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 675–676why, one step back675 "value, expected",676 (Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 677–678why, one step back677 (678 '<http:/.../front.jpeg>; rel=front; type="image/jpeg"',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 679why, one step back679 [{"url": "http:/.../front.jpeg", "rel": "front", "type": "image/jpeg"}],Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 680why, one step back680 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 681–682why, one step back681 ("<http:/.../front.jpeg>", [{"url": "http:/.../front.jpeg"}]),682 ("<http:/.../front.jpeg>;", [{"url": "http:/.../front.jpeg"}]),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 683–685why, one step back683 (684 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',685 [Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 686–688why, one step back686 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},687 {"url": "http://.../back.jpeg"},688 ],Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 689why, one step back689 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 690–692why, one step back690 ("", []),691 ),692)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 693–697why, one step back693def test_parse_header_links(value, expected):694 assert parse_header_links(value) == expected695696697@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 698–702why, one step back698 "value, expected",699 (700 ("example.com/path", "http://example.com/path"),701 ("//example.com/path", "http://example.com/path"),702 ("example.com:80", "http://example.com:80"),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 703why, one step back703 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 704–705why, one step back704 "http://user:pass@example.com/path?query",705 "http://user:pass@example.com/path?query",Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 706why, one step back706 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 707–709why, one step back707 ("http://user@example.com/path?query", "http://user@example.com/path?query"),708 ),709)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 710why, one step back710def test_prepend_scheme_if_needed(value, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 711why, one step back711 assert prepend_scheme_if_needed(value, "http") == expectedUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 712–714why, one step back712713714@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 715–721why, one step back715 "value, expected",716 (717 ("T", "T"),718 (b"T", "T"),719 ("T", "T"),720 ),721)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 722–726why, one step back722def test_to_native_string(value, expected):723 assert to_native_string(value) == expected724725726@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 727–736why, one step back727 "url, expected",728 (729 ("http://u:p@example.com/path?a=1#test", "http://example.com/path?a=1"),730 ("http://example.com/path", "http://example.com/path"),731 ("//u:p@example.com/path", "//example.com/path"),732 ("//example.com/path", "//example.com/path"),733 ("example.com/path", "//example.com/path"),734 ("scheme:u:p@example.com/path", "scheme://example.com/path"),735 ),736)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 737–741why, one step back737def test_urldefragauth(url, expected):738 assert urldefragauth(url) == expected739740741@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 742–755why, one step back742 "url, expected",743 (744 ("http://192.168.0.1:5000/", True),745 ("http://192.168.0.1/", True),746 ("http://172.16.1.1/", True),747 ("http://172.16.1.1:5000/", True),748 ("http://localhost.localdomain:5000/v1.0/", True),749 ("http://google.com:6000/", True),750 ("http://172.16.1.12/", False),751 ("http://172.16.1.12:5000/", False),752 ("http://google.com:5000/v1.0/", False),753 ("file:///some/path/on/disk", True),754 ),755)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 756–759why, one step back756def test_should_bypass_proxies(url, expected, monkeypatch):757 """Tests for function should_bypass_proxies to check if proxy758 can be bypassed or not759 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 760–767why, one step back760 monkeypatch.setenv(761 "no_proxy",762 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",763 )764 monkeypatch.setenv(765 "NO_PROXY",766 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",767 )Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 768–771why, one step back768 assert should_bypass_proxies(url, no_proxy=None) == expected769770771@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 772–783why, one step back772 "url, expected",773 (774 ("http://172.16.1.1/", "172.16.1.1"),775 ("http://172.16.1.1:5000/", "172.16.1.1"),776 ("http://user:pass@172.16.1.1", "172.16.1.1"),777 ("http://user:pass@172.16.1.1:5000", "172.16.1.1"),778 ("http://hostname/", "hostname"),779 ("http://hostname:5000/", "hostname"),780 ("http://user:pass@hostname", "hostname"),781 ("http://user:pass@hostname:5000", "hostname"),782 ),783)Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 784why, one step back784def test_should_bypass_proxies_pass_only_hostname(url, expected):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 785–787why, one step back785 """The proxy_bypass function should be called with a hostname or IP without786 a port number or auth credentials.787 """Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
lines 788–790why, one step back788 with mock.patch("requests.utils.proxy_bypass") as proxy_bypass:789 should_bypass_proxies(url, no_proxy=None)790 proxy_bypass.assert_called_once_with(expected)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 791–793why, one step back791792793@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 794–795why, one step back794 "cookiejar",795 (Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 796why, one step back796 compat.cookielib.CookieJar(),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 797–799why, one step back797 RequestsCookieJar(),798 ),799)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 800–803why, one step back800def test_add_dict_to_cookiejar(cookiejar):801 """Ensure add_dict_to_cookiejar works for802 non-RequestsCookieJar CookieJars803 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 804why, one step back804 cookiedict = {"test": "cookies", "good": "cookies"}Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 805–810why, one step back805 cj = add_dict_to_cookiejar(cookiejar, cookiedict)806 cookies = {cookie.name: cookie.value for cookie in cj}807 assert cookiedict == cookies808809810@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 811–816why, one step back811 "value, expected",812 (813 ("test", True),814 ("æíöû", False),815 ("ジェーピーニック", False),816 ),Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 817–822why, one step back817)818def test_unicode_is_ascii(value, expected):819 assert unicode_is_ascii(value) is expected820821822@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 823–835why, one step back823 "url, expected",824 (825 ("http://192.168.0.1:5000/", True),826 ("http://192.168.0.1/", True),827 ("http://172.16.1.1/", True),828 ("http://172.16.1.1:5000/", True),829 ("http://localhost.localdomain:5000/v1.0/", True),830 ("http://172.16.1.12/", False),831 ("http://172.16.1.12:5000/", False),832 ("http://google.com:5000/v1.0/", False),833 ),834)835def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 836–838why, one step back836 """Tests for function should_bypass_proxies to check if proxy837 can be bypassed or not using the 'no_proxy' argument838 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 839why, one step back839 no_proxy = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 840–843why, one step back840 # Test 'no_proxy' argument841 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected842843Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 844why, one step back844@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 845why, one step back845@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 846–860why, one step back846 "url, expected, override",847 (848 ("http://192.168.0.1:5000/", True, None),849 ("http://192.168.0.1/", True, None),850 ("http://172.16.1.1/", True, None),851 ("http://172.16.1.1:5000/", True, None),852 ("http://localhost.localdomain:5000/v1.0/", True, None),853 ("http://172.16.1.22/", False, None),854 ("http://172.16.1.22:5000/", False, None),855 ("http://google.com:5000/v1.0/", False, None),856 ("http://mylocalhostname:5000/v1.0/", True, "<local>"),857 ("http://192.168.0.1/", False, ""),858 ),859)860def test_should_bypass_proxies_win_registry(url, expected, override, monkeypatch):Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 861–864why, one step back861 """Tests for function should_bypass_proxies to check if proxy862 can be bypassed or not with Windows registry settings863 """864 if override is None:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 865why, one step back865 override = "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583
line 866why, one step back866 import winregUpdate quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 867–879why, one step back867868 class RegHandle:869 def Close(self):870 pass871872 ie_settings = RegHandle()873 proxyEnableValues = deque([1, "1"])874875 def OpenKey(key, subkey):876 return ie_settings877878 def QueryValueEx(key, value_name):879 if key is ie_settings:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 880why, one step back880 if value_name == "ProxyEnable":Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 881–883why, one step back881 # this could be a string (REG_SZ) or a 32-bit number (REG_DWORD)882 proxyEnableValues.rotate()883 return [proxyEnableValues[0]]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 884why, one step back884 elif value_name == "ProxyOverride":Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 885–886why, one step back885 return [override]886Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 887–893why, one step back887 monkeypatch.setenv("http_proxy", "")888 monkeypatch.setenv("https_proxy", "")889 monkeypatch.setenv("ftp_proxy", "")890 monkeypatch.setenv("no_proxy", "")891 monkeypatch.setenv("NO_PROXY", "")892 monkeypatch.setattr(winreg, "OpenKey", OpenKey)893 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 894–896why, one step back894 assert should_bypass_proxies(url, None) == expected895896Tolerate bad registry entries in Windows proxy settings (#6149)Nate Prewittbefore adoption210095f
lines 897–929why, one step back897@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")898def test_should_bypass_proxies_win_registry_bad_values(monkeypatch):899 """Tests for function should_bypass_proxies to check if proxy900 can be bypassed or not with Windows invalid registry settings.901 """902 import winreg903904 class RegHandle:905 def Close(self):906 pass907908 ie_settings = RegHandle()909910 def OpenKey(key, subkey):911 return ie_settings912913 def QueryValueEx(key, value_name):914 if key is ie_settings:915 if value_name == "ProxyEnable":916 # Invalid response; Should be an int or int-y value917 return [""]918 elif value_name == "ProxyOverride":919 return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"]920921 monkeypatch.setenv("http_proxy", "")922 monkeypatch.setenv("https_proxy", "")923 monkeypatch.setenv("no_proxy", "")924 monkeypatch.setenv("NO_PROXY", "")925 monkeypatch.setattr(winreg, "OpenKey", OpenKey)926 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)927 assert should_bypass_proxies("http://172.16.1.1/", None) is False928929Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 930why, one step back930@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 931–938why, one step back931 "env_name, value",932 (933 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),934 ("no_proxy", None),935 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),936 ("a_new_key", None),937 ),938)Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
lines 939–951why, one step back939def test_set_environ(env_name, value):940 """Tests set_environ will set environ values and will restore the environ."""941 environ_copy = copy.deepcopy(os.environ)942 with set_environ(env_name, value):943 assert os.environ.get(env_name) == value944945 assert os.environ == environ_copy946947948def test_set_environ_raises_exception():949 """Tests set_environ will raise exceptions in context when the950 value parameter is None."""951 with pytest.raises(Exception) as exception:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 952–953why, one step back952 with set_environ("test1", None):953 raise Exception("Expected exception")Update quickstart.rst : fixing brotlicffi link (#6044)Chavithrabefore adoption24dfbfd
line 954why, one step back954Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 955why, one step back955 assert "Expected exception" in str(exception.value)Merge pull request #6302 from flysee/mainIan Stapleton Cordascobefore adoption8dd3b26
lines 956–987why, one step back956957958@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")959def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):960 """Tests for function should_bypass_proxies to check if proxy961 can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.962 """963 import winreg964965 class RegHandle:966 def Close(self):967 pass968969 ie_settings = RegHandle()970971 def OpenKey(key, subkey):972 return ie_settings973974 def QueryValueEx(key, value_name):975 if key is ie_settings:976 if value_name == "ProxyEnable":977 return [1]978 elif value_name == "ProxyOverride":979 return [980 "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"981 ]982983 monkeypatch.setenv("NO_PROXY", "")984 monkeypatch.setenv("no_proxy", "")985 monkeypatch.setattr(winreg, "OpenKey", OpenKey)986 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)987 assert should_bypass_proxies("http://example.com/", None) is False