test_utils.py
This file
Path
tests/test_utils.py
925 lines · 27.6 KiB · Python
Last changed by
Tolerate bad registry entries in Windows proxy settings (#6149)Nate Prewittbefore adoption210095f
History of this fileTake it
The walk stopped after 200 commits: lines older than 782e94d point at it.
Update example code in README.md (#5292)John Kookerbefore adoption782e94d
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 tarfileUpdate example code in README.md (#5292)John Kookerbefore adoption782e94d
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 BytesIOUpdate example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 8–9why, one step back89import pytestAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 10why, one step back10Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 11why, one step back11from requests import compatAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 12why, one step back12from requests._internal_utils import unicode_is_asciiUpdate example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 13–15why, one step back13from requests.cookies import RequestsCookieJar14from requests.structures import CaseInsensitiveDict15from requests.utils import (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 16–43why, one step back16 _parse_content_type_header,17 add_dict_to_cookiejar,18 address_in_network,19 dotted_netmask,20 extract_zipped_paths,21 get_auth_from_url,22 get_encoding_from_headers,23 get_encodings_from_content,24 get_environ_proxies,25 guess_filename,26 guess_json_utf,27 is_ipv4_address,28 is_valid_cidr,29 iter_slices,30 parse_dict_header,31 parse_header_links,32 prepend_scheme_if_needed,33 requote_uri,34 select_proxy,35 set_environ,36 should_bypass_proxies,37 super_len,38 to_key_val_list,39 to_native_string,40 unquote_header_value,41 unquote_unreserved,42 urldefragauth,43)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 44–49why, one step back4445from .compat import StringIO, cStringIO464748class TestSuperLen:49 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 50–58why, one step back50 "stream, value",51 (52 (StringIO.StringIO, "Test"),53 (BytesIO, b"Test"),54 pytest.param(55 cStringIO, "Test", marks=pytest.mark.skipif("cStringIO is None")56 ),57 ),58 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 59–66why, one step back59 def test_io_streams(self, stream, value):60 """Ensures that we properly deal with different kinds of IO streams."""61 assert super_len(stream()) == 062 assert super_len(stream(value)) == 46364 def test_super_len_correctly_calculates_len_of_partially_read_file(self):65 """Ensure that we handle partially consumed file like objects."""66 s = StringIO.StringIO()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 67why, one step back67 s.write("foobarbogus")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 68–69why, one step back68 assert super_len(s) == 069Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 70why, one step back70 @pytest.mark.parametrize("error", [IOError, OSError])Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 71–72why, one step back71 def test_super_len_handles_files_raising_weird_errors_in_tell(self, error):72 """If tell() raises errors, assume the cursor is at position zero."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 73–74why, one step back7374 class BoomFile:Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 75–82why, one step back75 def __len__(self):76 return 57778 def tell(self):79 raise error()8081 assert super_len(BoomFile()) == 082Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 83why, one step back83 @pytest.mark.parametrize("error", [IOError, OSError])Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 84–85why, one step back84 def test_super_len_tell_ioerror(self, error):85 """Ensure that if tell gives an IOError super_len doesn't fail"""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 86–87why, one step back8687 class NoLenBoomFile:Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 88–96why, one step back88 def tell(self):89 raise error()9091 def seek(self, offset, whence):92 pass9394 assert super_len(NoLenBoomFile()) == 09596 def test_string(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 97why, one step back97 assert super_len("Test") == 4Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 98–99why, one step back9899 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 100–105why, one step back100 "mode, warnings_num",101 (102 ("r", 1),103 ("rb", 0),104 ),105 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 106why, one step back106 def test_file(self, tmpdir, mode, warnings_num, recwarn):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 107–108why, one step back107 file_obj = tmpdir.join("test.txt")108 file_obj.write("Test")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 109–111why, one step back109 with file_obj.open(mode) as fd:110 assert super_len(fd) == 4111 assert len(recwarn) == warnings_numCatch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
lines 112–113why, one step back112113 def test_tarfile_member(self, tmpdir):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 114–115why, one step back114 file_obj = tmpdir.join("test.txt")115 file_obj.write("Test")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 116why, one step back116Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 117–119why, one step back117 tar_obj = str(tmpdir.join("test.tar"))118 with tarfile.open(tar_obj, "w") as tar:119 tar.add(str(file_obj), arcname="test.txt")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
lines 120–121why, one step back120121 with tarfile.open(tar_obj) as tar:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 122why, one step back122 member = tar.extractfile("test.txt")Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e
line 123why, one step back123 assert super_len(member) == 4Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 124–125why, one step back124125 def test_super_len_with__len__(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 126why, one step back126 foo = [1, 2, 3, 4]Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 127–130why, one step back127 len_foo = super_len(foo)128 assert len_foo == 4129130 def test_super_len_with_no__len__(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 131why, one step back131 class LenFile:Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 132–137why, one step back132 def __init__(self):133 self.len = 5134135 assert super_len(LenFile()) == 5136137 def test_super_len_with_tell(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 138why, one step back138 foo = StringIO.StringIO("12345")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 139–143why, one step back139 assert super_len(foo) == 5140 foo.read(2)141 assert super_len(foo) == 3142143 def test_super_len_with_fileno(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 144why, one step back144 with open(__file__, "rb") as f:Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 145–155why, one step back145 length = super_len(f)146 file_data = f.read()147 assert length == len(file_data)148149 def test_super_len_with_no_matches(self):150 """Ensure that objects without any length methods default to 0"""151 assert super_len(object()) == 0152153154class TestToKeyValList:155 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 156–163why, one step back156 "value, expected",157 (158 ([("key", "val")], [("key", "val")]),159 ((("key", "val"),), [("key", "val")]),160 ({"key": "val"}, [("key", "val")]),161 (None, None),162 ),163 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 164–168why, one step back164 def test_valid(self, value, expected):165 assert to_key_val_list(value) == expected166167 def test_invalid(self):168 with pytest.raises(ValueError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 169why, one step back169 to_key_val_list("string")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 170–173why, one step back170171172class TestUnquoteHeaderValue:173 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 174–175why, one step back174 "value, expected",175 (Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 176why, one step back176 (None, None),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 177–182why, one step back177 ("Test", "Test"),178 ('"Test"', "Test"),179 ('"Test\\\\"', "Test\\"),180 ('"\\\\Comp\\Res"', "\\Comp\\Res"),181 ),182 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 183–186why, one step back183 def test_valid(self, value, expected):184 assert unquote_header_value(value) == expected185186 def test_is_filename(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 187why, one step back187 assert unquote_header_value('"\\\\Comp\\Res"', True) == "\\\\Comp\\Res"Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 188–194why, one step back188189190class TestGetEnvironProxies:191 """Ensures that IP addresses are correctly matches with ranges192 in no_proxy variable.193 """194Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 195why, one step back195 @pytest.fixture(autouse=True, params=["no_proxy", "NO_PROXY"])Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 196why, one step back196 def no_proxy(self, request, monkeypatch):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 197–199why, one step back197 monkeypatch.setenv(198 request.param, "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"199 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 200–201why, one step back200201 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 202–210why, one step back202 "url",203 (204 "http://192.168.0.1:5000/",205 "http://192.168.0.1/",206 "http://172.16.1.1/",207 "http://172.16.1.1:5000/",208 "http://localhost.localdomain:5000/v1.0/",209 ),210 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 211–214why, one step back211 def test_bypass(self, url):212 assert get_environ_proxies(url, no_proxy=None) == {}213214 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 215–221why, one step back215 "url",216 (217 "http://192.168.1.1:5000/",218 "http://192.168.1.1/",219 "http://www.requests.com/",220 ),221 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 222–225why, one step back222 def test_not_bypass(self, url):223 assert get_environ_proxies(url, no_proxy=None) != {}224225 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 226–232why, one step back226 "url",227 (228 "http://192.168.1.1:5000/",229 "http://192.168.1.1/",230 "http://www.requests.com/",231 ),232 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 233why, one step back233 def test_bypass_no_proxy_keyword(self, url):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 234why, one step back234 no_proxy = "192.168.1.1,requests.com"Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 235–237why, one step back235 assert get_environ_proxies(url, no_proxy=no_proxy) == {}236237 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 238–246why, one step back238 "url",239 (240 "http://192.168.0.1:5000/",241 "http://192.168.0.1/",242 "http://172.16.1.1/",243 "http://172.16.1.1:5000/",244 "http://localhost.localdomain:5000/v1.0/",245 ),246 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 247–249why, one step back247 def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):248 # This is testing that the 'no_proxy' argument overrides the249 # environment variable 'no_proxy'Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 250–251why, one step back250 monkeypatch.setenv("http_proxy", "http://proxy.example.com:3128/")251 no_proxy = "192.168.1.1,requests.com"Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 252–256why, one step back252 assert get_environ_proxies(url, no_proxy=no_proxy) != {}253254255class TestIsIPv4Address:256 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 257why, one step back257 assert is_ipv4_address("8.8.8.8")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 258why, one step back258Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 259why, one step back259 @pytest.mark.parametrize("value", ("8.8.8.8.8", "localhost.localdomain"))Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 260–265why, one step back260 def test_invalid(self, value):261 assert not is_ipv4_address(value)262263264class TestIsValidCIDR:265 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 266why, one step back266 assert is_valid_cidr("192.168.1.0/24")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 267–268why, one step back267268 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 269–277why, one step back269 "value",270 (271 "8.8.8.8",272 "192.168.1.0/a",273 "192.168.1.0/128",274 "192.168.1.0/-1",275 "192.168.1.999/24",276 ),277 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 278–283why, one step back278 def test_invalid(self, value):279 assert not is_valid_cidr(value)280281282class TestAddressInNetwork:283 def test_valid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 284why, one step back284 assert address_in_network("192.168.1.1", "192.168.1.0/24")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 285–286why, one step back285286 def test_invalid(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 287why, one step back287 assert not address_in_network("172.16.0.1", "192.168.1.0/24")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 288–291why, one step back288289290class TestGuessFilename:291 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 292–293why, one step back292 "value",293 (1, type("Fake", (object,), {"name": 1})()),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 294–298why, one step back294 )295 def test_guess_filename_invalid(self, value):296 assert guess_filename(value) is None297298 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 299–304why, one step back299 "value, expected_type",300 (301 (b"value", compat.bytes),302 (b"value".decode("utf-8"), compat.str),303 ),304 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 305why, one step back305 def test_guess_filename_valid(self, value, expected_type):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 306why, one step back306 obj = type("Fake", (object,), {"name": value})()Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 307–313why, one step back307 result = guess_filename(obj)308 assert result == value309 assert isinstance(result, expected_type)310311312class TestExtractZippedPaths:313 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 314–316why, one step back314 "path",315 (316 "/",Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 317–318why, one step back317 __file__,318 pytest.__file__,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 319–321why, one step back319 "/etc/invalid/location",320 ),321 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 322–325why, one step back322 def test_unzipped_paths_unchanged(self, path):323 assert path == extract_zipped_paths(path)324325 def test_zipped_paths_extracted(self, tmpdir):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 326–327why, one step back326 zipped_py = tmpdir.join("test.zip")327 with zipfile.ZipFile(zipped_py.strpath, "w") as f:Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 328–330why, one step back328 f.write(__file__)329330 _, name = os.path.splitdrive(__file__)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 331why, one step back331 zipped_path = os.path.join(zipped_py.strpath, name.lstrip(r"\/"))Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 332–337why, one step back332 extracted_path = extract_zipped_paths(zipped_path)333334 assert extracted_path != zipped_path335 assert os.path.exists(extracted_path)336 assert filecmp.cmp(extracted_path, __file__)337Fix extract_zipped_paths infinite loop when provided invalid unc path (#5851)Thomas Lambefore adoptiond8829f9
lines 338–341why, one step back338 def test_invalid_unc_path(self):339 path = r"\\localhost\invalid\location"340 assert extract_zipped_paths(path) == path341Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 342–344why, one step back342343class TestContentEncodingDetection:344 def test_none(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 345why, one step back345 encodings = get_encodings_from_content("")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 346–348why, one step back346 assert not len(encodings)347348 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 349–350why, one step back349 "content",350 (Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 351–358why, one step back351 # HTML5 meta charset attribute352 '<meta charset="UTF-8">',353 # HTML4 pragma directive354 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',355 # XHTML 1.x served with text/html MIME type356 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',357 # XHTML 1.x served as XML358 '<?xml version="1.0" encoding="UTF-8"?>',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 359–360why, one step back359 ),360 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 361–363why, one step back361 def test_pragmas(self, content):362 encodings = get_encodings_from_content(content)363 assert len(encodings) == 1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 364why, one step back364 assert encodings[0] == "UTF-8"Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 365–366why, one step back365366 def test_precedence(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 367why, one step back367 content = """Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 368–370why, one step back368 <?xml version="1.0" encoding="XML"?>369 <meta charset="HTML5">370 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 371–372why, one step back371 """.strip()372 assert get_encodings_from_content(content) == ["HTML5", "HTML4", "XML"]Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 373–376why, one step back373374375class TestGuessJSONUTF:376 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 377–388why, one step back377 "encoding",378 (379 "utf-32",380 "utf-8-sig",381 "utf-16",382 "utf-8",383 "utf-16-be",384 "utf-16-le",385 "utf-32-be",386 "utf-32-le",387 ),388 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 389why, one step back389 def test_encoded(self, encoding):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 390why, one step back390 data = "{}".encode(encoding)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 391–393why, one step back391 assert guess_json_utf(data) == encoding392393 def test_bad_utf_like_encoding(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 394why, one step back394 assert guess_json_utf(b"\x00\x00\x00\x00") is NoneUpdate example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 395–396why, one step back395396 @pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 397–404why, one step back397 ("encoding", "expected"),398 (399 ("utf-16-be", "utf-16"),400 ("utf-16-le", "utf-16"),401 ("utf-32-be", "utf-32"),402 ("utf-32-le", "utf-32"),403 ),404 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 405why, one step back405 def test_guess_by_bom(self, encoding, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 406why, one step back406 data = "\ufeff{}".encode(encoding)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 407–410why, one step back407 assert guess_json_utf(data) == expected408409410USER = PASSWORD = "%!*'();:@&=+$,/?#[] "Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 411–412why, one step back411ENCODED_USER = compat.quote(USER, "")412ENCODED_PASSWORD = compat.quote(PASSWORD, "")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 413–415why, one step back413414415@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 416–417why, one step back416 "url, auth",417 (Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 418why, one step back418 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 419–420why, one step back419 f"http://{ENCODED_USER}:{ENCODED_PASSWORD}@request.com/url.html#test",420 (USER, PASSWORD),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 421why, one step back421 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 422why, one step back422 ("http://user:pass@complex.url.com/path?query=yes", ("user", "pass")),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 423why, one step back423 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 424–425why, one step back424 "http://user:pass%20pass@complex.url.com/path?query=yes",425 ("user", "pass pass"),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 426why, one step back426 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 427why, one step back427 ("http://user:pass pass@complex.url.com/path?query=yes", ("user", "pass pass")),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 428why, one step back428 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 429–430why, one step back429 "http://user%25user:pass@complex.url.com/path?query=yes",430 ("user%user", "pass"),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 431–432why, one step back431 ),432 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 433–434why, one step back433 "http://user:pass%23pass@complex.url.com/path?query=yes",434 ("user", "pass#pass"),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 435why, one step back435 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 436–438why, one step back436 ("http://complex.url.com/path?query=yes", ("", "")),437 ),438)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 439–443why, one step back439def test_get_auth_from_url(url, auth):440 assert get_auth_from_url(url) == auth441442443@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 444–445why, one step back444 "uri, expected",445 (Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 446–447why, one step back446 (447 # Ensure requoting doesn't break expectationsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 448–449why, one step back448 "http://example.com/fiz?buz=%25ppicture",449 "http://example.com/fiz?buz=%25ppicture",Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 450–452why, one step back450 ),451 (452 # Ensure we handle unquoted percent signs in redirectsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 453–454why, one step back453 "http://example.com/fiz?buz=%ppicture",454 "http://example.com/fiz?buz=%25ppicture",Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 455why, one step back455 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 456–457why, one step back456 ),457)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 458–463why, one step back458def test_requote_uri_with_unquoted_percents(uri, expected):459 """See: https://github.com/psf/requests/issues/2356"""460 assert requote_uri(uri) == expected461462463@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 464–465why, one step back464 "uri, expected",465 (Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 466–467why, one step back466 (467 # Illegal bytesAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 468–469why, one step back468 "http://example.com/?a=%--",469 "http://example.com/?a=%--",Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 470–472why, one step back470 ),471 (472 # Reserved charactersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 473–477why, one step back473 "http://example.com/?a=%300",474 "http://example.com/?a=00",475 ),476 ),477)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 478–482why, one step back478def test_unquote_unreserved(uri, expected):479 assert unquote_unreserved(uri) == expected480481482@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 483–489why, one step back483 "mask, expected",484 (485 (8, "255.0.0.0"),486 (24, "255.255.255.0"),487 (25, "255.255.255.128"),488 ),489)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 490–493why, one step back490def test_dotted_netmask(mask, expected):491 assert dotted_netmask(mask) == expected492493Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 494–506why, one step back494http_proxies = {495 "http": "http://http.proxy",496 "http://some.host": "http://some.host.proxy",497}498all_proxies = {499 "all": "socks5://http.proxy",500 "all://some.host": "socks5://some.host.proxy",501}502mixed_proxies = {503 "http": "http://http.proxy",504 "http://some.host": "http://some.host.proxy",505 "all": "socks5://http.proxy",506}Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 507–508why, one step back507508Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 509–525why, one step back509@pytest.mark.parametrize(510 "url, expected, proxies",511 (512 ("hTTp://u:p@Some.Host/path", "http://some.host.proxy", http_proxies),513 ("hTTp://u:p@Other.Host/path", "http://http.proxy", http_proxies),514 ("hTTp:///path", "http://http.proxy", http_proxies),515 ("hTTps://Other.Host", None, http_proxies),516 ("file:///etc/motd", None, http_proxies),517 ("hTTp://u:p@Some.Host/path", "socks5://some.host.proxy", all_proxies),518 ("hTTp://u:p@Other.Host/path", "socks5://http.proxy", all_proxies),519 ("hTTp:///path", "socks5://http.proxy", all_proxies),520 ("hTTps://Other.Host", "socks5://http.proxy", all_proxies),521 ("http://u:p@other.host/path", "http://http.proxy", mixed_proxies),522 ("http://u:p@some.host/path", "http://some.host.proxy", mixed_proxies),523 ("https://u:p@other.host/path", "socks5://http.proxy", mixed_proxies),524 ("https://u:p@some.host/path", "socks5://http.proxy", mixed_proxies),525 ("https://", "socks5://http.proxy", mixed_proxies),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 526why, one step back526 # XXX: unsure whether this is reasonable behaviorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 527–529why, one step back527 ("file:///etc/motd", "socks5://http.proxy", all_proxies),528 ),529)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 530–535why, one step back530def test_select_proxies(url, expected, proxies):531 """Make sure we can select per-host proxies correctly."""532 assert select_proxy(url, proxies) == expected533534535@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 536–541why, one step back536 "value, expected",537 (538 ('foo="is a fish", bar="as well"', {"foo": "is a fish", "bar": "as well"}),539 ("key_without_value", {"key_without_value": None}),540 ),541)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 542–546why, one step back542def test_parse_dict_header(value, expected):543 assert parse_dict_header(value) == expected544545546@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 547–549why, one step back547 "value, expected",548 (549 ("application/xml", ("application/xml", {})),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 550why, one step back550 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 551–552why, one step back551 "application/json ; charset=utf-8",552 ("application/json", {"charset": "utf-8"}),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 553–554why, one step back553 ),554 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 555–556why, one step back555 "application/json ; Charset=utf-8",556 ("application/json", {"charset": "utf-8"}),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 557why, one step back557 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 558why, one step back558 ("text/plain", ("text/plain", {})),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 559why, one step back559 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 560–568why, one step back560 "multipart/form-data; boundary = something ; boundary2='something_else' ; no_equals ",561 (562 "multipart/form-data",563 {564 "boundary": "something",565 "boundary2": "something_else",566 "no_equals": True,567 },568 ),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 569–570why, one step back569 ),570 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 571–579why, one step back571 'multipart/form-data; boundary = something ; boundary2="something_else" ; no_equals ',572 (573 "multipart/form-data",574 {575 "boundary": "something",576 "boundary2": "something_else",577 "no_equals": True,578 },579 ),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 580–581why, one step back580 ),581 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 582–590why, one step back582 "multipart/form-data; boundary = something ; 'boundary2=something_else' ; no_equals ",583 (584 "multipart/form-data",585 {586 "boundary": "something",587 "boundary2": "something_else",588 "no_equals": True,589 },590 ),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 591–593why, one step back591 ),592 (593 'multipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals ',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 594–601why, one step back594 (595 "multipart/form-data",596 {597 "boundary": "something",598 "boundary2": "something_else",599 "no_equals": True,600 },601 ),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 602why, one step back602 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 603–605why, one step back603 ("application/json ; ; ", ("application/json", {})),604 ),605)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 606–610why, one step back606def test__parse_content_type_header(value, expected):607 assert _parse_content_type_header(value) == expected608609610@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 611–613why, one step back611 "value, expected",612 (613 (CaseInsensitiveDict(), None),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 614why, one step back614 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 615–616why, one step back615 CaseInsensitiveDict({"content-type": "application/json; charset=utf-8"}),616 "utf-8",Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 617why, one step back617 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 618–620why, one step back618 (CaseInsensitiveDict({"content-type": "text/plain"}), "ISO-8859-1"),619 ),620)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 621–625why, one step back621def test_get_encoding_from_headers(value, expected):622 assert get_encoding_from_headers(value) == expected623624625@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 626–635why, one step back626 "value, length",627 (628 ("", 0),629 ("T", 1),630 ("Test", 4),631 ("Cont", 0),632 ("Other", -5),633 ("Content", None),634 ),635)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 636–644why, one step back636def test_iter_slices(value, length):637 if length is None or (length <= 0 and len(value) > 0):638 # Reads all content at once639 assert len(list(iter_slices(value, length))) == 1640 else:641 assert len(list(iter_slices(value, 1))) == length642643644@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 645–646why, one step back645 "value, expected",646 (Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 647–648why, one step back647 (648 '<http:/.../front.jpeg>; rel=front; type="image/jpeg"',Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 649why, one step back649 [{"url": "http:/.../front.jpeg", "rel": "front", "type": "image/jpeg"}],Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 650why, one step back650 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 651–652why, one step back651 ("<http:/.../front.jpeg>", [{"url": "http:/.../front.jpeg"}]),652 ("<http:/.../front.jpeg>;", [{"url": "http:/.../front.jpeg"}]),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 653–655why, one step back653 (654 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',655 [Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 656–658why, one step back656 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},657 {"url": "http://.../back.jpeg"},658 ],Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 659why, one step back659 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 660–662why, one step back660 ("", []),661 ),662)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 663–667why, one step back663def test_parse_header_links(value, expected):664 assert parse_header_links(value) == expected665666667@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 668–672why, one step back668 "value, expected",669 (670 ("example.com/path", "http://example.com/path"),671 ("//example.com/path", "http://example.com/path"),672 ("example.com:80", "http://example.com:80"),Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724
line 673why, one step back673 (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 674–675why, one step back674 "http://user:pass@example.com/path?query",675 "http://user:pass@example.com/path?query",Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724
line 676why, one step back676 ),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 677–679why, one step back677 ("http://user@example.com/path?query", "http://user@example.com/path?query"),678 ),679)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 680why, one step back680def test_prepend_scheme_if_needed(value, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 681why, one step back681 assert prepend_scheme_if_needed(value, "http") == expectedUpdate example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 682–684why, one step back682683684@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 685–691why, one step back685 "value, expected",686 (687 ("T", "T"),688 (b"T", "T"),689 ("T", "T"),690 ),691)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 692–696why, one step back692def test_to_native_string(value, expected):693 assert to_native_string(value) == expected694695696@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 697–706why, one step back697 "url, expected",698 (699 ("http://u:p@example.com/path?a=1#test", "http://example.com/path?a=1"),700 ("http://example.com/path", "http://example.com/path"),701 ("//u:p@example.com/path", "//example.com/path"),702 ("//example.com/path", "//example.com/path"),703 ("example.com/path", "//example.com/path"),704 ("scheme:u:p@example.com/path", "scheme://example.com/path"),705 ),706)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 707–711why, one step back707def test_urldefragauth(url, expected):708 assert urldefragauth(url) == expected709710711@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 712–725why, one step back712 "url, expected",713 (714 ("http://192.168.0.1:5000/", True),715 ("http://192.168.0.1/", True),716 ("http://172.16.1.1/", True),717 ("http://172.16.1.1:5000/", True),718 ("http://localhost.localdomain:5000/v1.0/", True),719 ("http://google.com:6000/", True),720 ("http://172.16.1.12/", False),721 ("http://172.16.1.12:5000/", False),722 ("http://google.com:5000/v1.0/", False),723 ("file:///some/path/on/disk", True),724 ),725)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 726–729why, one step back726def test_should_bypass_proxies(url, expected, monkeypatch):727 """Tests for function should_bypass_proxies to check if proxy728 can be bypassed or not729 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 730–737why, one step back730 monkeypatch.setenv(731 "no_proxy",732 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",733 )734 monkeypatch.setenv(735 "NO_PROXY",736 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",737 )Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 738–741why, one step back738 assert should_bypass_proxies(url, no_proxy=None) == expected739740741@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 742–753why, one step back742 "url, expected",743 (744 ("http://172.16.1.1/", "172.16.1.1"),745 ("http://172.16.1.1:5000/", "172.16.1.1"),746 ("http://user:pass@172.16.1.1", "172.16.1.1"),747 ("http://user:pass@172.16.1.1:5000", "172.16.1.1"),748 ("http://hostname/", "hostname"),749 ("http://hostname:5000/", "hostname"),750 ("http://user:pass@hostname", "hostname"),751 ("http://user:pass@hostname:5000", "hostname"),752 ),753)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 754–757why, one step back754def test_should_bypass_proxies_pass_only_hostname(url, expected, mocker):755 """The proxy_bypass function should be called with a hostname or IP without756 a port number or auth credentials.757 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 758why, one step back758 proxy_bypass = mocker.patch("requests.utils.proxy_bypass")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 759–763why, one step back759 should_bypass_proxies(url, no_proxy=None)760 proxy_bypass.assert_called_once_with(expected)761762763@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 764–765why, one step back764 "cookiejar",765 (Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 766why, one step back766 compat.cookielib.CookieJar(),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 767–769why, one step back767 RequestsCookieJar(),768 ),769)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 770–773why, one step back770def test_add_dict_to_cookiejar(cookiejar):771 """Ensure add_dict_to_cookiejar works for772 non-RequestsCookieJar CookieJars773 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 774why, one step back774 cookiedict = {"test": "cookies", "good": "cookies"}Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 775–780why, one step back775 cj = add_dict_to_cookiejar(cookiejar, cookiedict)776 cookies = {cookie.name: cookie.value for cookie in cj}777 assert cookiedict == cookies778779780@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 781–786why, one step back781 "value, expected",782 (783 ("test", True),784 ("æíöû", False),785 ("ジェーピーニック", False),786 ),Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 787–792why, one step back787)788def test_unicode_is_ascii(value, expected):789 assert unicode_is_ascii(value) is expected790791792@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 793–805why, one step back793 "url, expected",794 (795 ("http://192.168.0.1:5000/", True),796 ("http://192.168.0.1/", True),797 ("http://172.16.1.1/", True),798 ("http://172.16.1.1:5000/", True),799 ("http://localhost.localdomain:5000/v1.0/", True),800 ("http://172.16.1.12/", False),801 ("http://172.16.1.12:5000/", False),802 ("http://google.com:5000/v1.0/", False),803 ),804)805def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 806–808why, one step back806 """Tests for function should_bypass_proxies to check if proxy807 can be bypassed or not using the 'no_proxy' argument808 """Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 809why, one step back809 no_proxy = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 810–813why, one step back810 # Test 'no_proxy' argument811 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected812813Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 814why, one step back814@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 815why, one step back815@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 816–830why, one step back816 "url, expected, override",817 (818 ("http://192.168.0.1:5000/", True, None),819 ("http://192.168.0.1/", True, None),820 ("http://172.16.1.1/", True, None),821 ("http://172.16.1.1:5000/", True, None),822 ("http://localhost.localdomain:5000/v1.0/", True, None),823 ("http://172.16.1.22/", False, None),824 ("http://172.16.1.22:5000/", False, None),825 ("http://google.com:5000/v1.0/", False, None),826 ("http://mylocalhostname:5000/v1.0/", True, "<local>"),827 ("http://192.168.0.1/", False, ""),828 ),829)830def test_should_bypass_proxies_win_registry(url, expected, override, monkeypatch):Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 831–834why, one step back831 """Tests for function should_bypass_proxies to check if proxy832 can be bypassed or not with Windows registry settings833 """834 if override is None:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 835why, one step back835 override = "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583
line 836why, one step back836 import winregUpdate example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 837–849why, one step back837838 class RegHandle:839 def Close(self):840 pass841842 ie_settings = RegHandle()843 proxyEnableValues = deque([1, "1"])844845 def OpenKey(key, subkey):846 return ie_settings847848 def QueryValueEx(key, value_name):849 if key is ie_settings:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 850why, one step back850 if value_name == "ProxyEnable":Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 851–853why, one step back851 # this could be a string (REG_SZ) or a 32-bit number (REG_DWORD)852 proxyEnableValues.rotate()853 return [proxyEnableValues[0]]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 854why, one step back854 elif value_name == "ProxyOverride":Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 855–856why, one step back855 return [override]856Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 857–863why, one step back857 monkeypatch.setenv("http_proxy", "")858 monkeypatch.setenv("https_proxy", "")859 monkeypatch.setenv("ftp_proxy", "")860 monkeypatch.setenv("no_proxy", "")861 monkeypatch.setenv("NO_PROXY", "")862 monkeypatch.setattr(winreg, "OpenKey", OpenKey)863 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 864–866why, one step back864 assert should_bypass_proxies(url, None) == expected865866Tolerate bad registry entries in Windows proxy settings (#6149)Nate Prewittbefore adoption210095f
lines 867–899why, one step back867@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")868def test_should_bypass_proxies_win_registry_bad_values(monkeypatch):869 """Tests for function should_bypass_proxies to check if proxy870 can be bypassed or not with Windows invalid registry settings.871 """872 import winreg873874 class RegHandle:875 def Close(self):876 pass877878 ie_settings = RegHandle()879880 def OpenKey(key, subkey):881 return ie_settings882883 def QueryValueEx(key, value_name):884 if key is ie_settings:885 if value_name == "ProxyEnable":886 # Invalid response; Should be an int or int-y value887 return [""]888 elif value_name == "ProxyOverride":889 return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"]890891 monkeypatch.setenv("http_proxy", "")892 monkeypatch.setenv("https_proxy", "")893 monkeypatch.setenv("no_proxy", "")894 monkeypatch.setenv("NO_PROXY", "")895 monkeypatch.setattr(winreg, "OpenKey", OpenKey)896 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)897 assert should_bypass_proxies("http://172.16.1.1/", None) is False898899Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 900why, one step back900@pytest.mark.parametrize(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 901–908why, one step back901 "env_name, value",902 (903 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),904 ("no_proxy", None),905 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),906 ("a_new_key", None),907 ),908)Update example code in README.md (#5292)John Kookerbefore adoption782e94d
lines 909–921why, one step back909def test_set_environ(env_name, value):910 """Tests set_environ will set environ values and will restore the environ."""911 environ_copy = copy.deepcopy(os.environ)912 with set_environ(env_name, value):913 assert os.environ.get(env_name) == value914915 assert os.environ == environ_copy916917918def test_set_environ_raises_exception():919 """Tests set_environ will raise exceptions in context when the920 value parameter is None."""921 with pytest.raises(Exception) as exception:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 922–923why, one step back922 with set_environ("test1", None):923 raise Exception("Expected exception")Update example code in README.md (#5292)John Kookerbefore adoption782e94d
line 924why, one step back924Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 925why, one step back925 assert "Expected exception" in str(exception.value)