Skip to content
Myr

test_utils.py

This file

Path

tests/test_utils.py

892 lines · 26.5 KiB · Python

Last changed by

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

History of this file

Take it

The walk stopped after 200 commits: lines older than 537ac3c point at it.

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 1–2why, one step back
1import copy
2import filecmp

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 3why, one step back
3import os

Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e

line 4why, one step back
4import tarfile

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 5–6why, one step back
5import zipfile
6from collections import deque

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 7why, one step back
7from io import BytesIO

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 8–9why, one step back
8
9import pytest

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 10why, one step back
10

Update README.mdKenneth Reitzbefore adoption537ac3c

line 11why, one step back
11from requests import compat

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 12why, one step back
12from requests._internal_utils import unicode_is_ascii

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 13–15why, one step back
13from requests.cookies import RequestsCookieJar
14from requests.structures import CaseInsensitiveDict15from requests.utils import (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 16–43why, one step back
16 _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 README.mdKenneth Reitzbefore adoption537ac3c

lines 44–49why, one step back
44
45from .compat import StringIO, cStringIO464748class TestSuperLen:49 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 50–58why, one step back
50 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 59–66why, one step back
59 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 back
67 s.write("foobarbogus")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 68–69why, one step back
68 assert super_len(s) == 0
69

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 70why, one step back
70 @pytest.mark.parametrize("error", [IOError, OSError])

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 71–72why, one step back
71 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 back
73
74 class BoomFile:

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 75–82why, one step back
75 def __len__(self):
76 return 57778 def tell(self):79 raise error()8081 assert super_len(BoomFile()) == 082

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 83why, one step back
83 @pytest.mark.parametrize("error", [IOError, OSError])

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 84–85why, one step back
84 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 back
86
87 class NoLenBoomFile:

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 88–96why, one step back
88 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 back
97 assert super_len("Test") == 4

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 98–99why, one step back
98
99 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 100–105why, one step back
100 "mode, warnings_num",
101 (102 ("r", 1),103 ("rb", 0),104 ),105 )

Update README.mdKenneth Reitzbefore adoption537ac3c

line 106why, one step back
106 def test_file(self, tmpdir, mode, warnings_num, recwarn):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 107–108why, one step back
107 file_obj = tmpdir.join("test.txt")
108 file_obj.write("Test")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 109–111why, one step back
109 with file_obj.open(mode) as fd:
110 assert super_len(fd) == 4111 assert len(recwarn) == warnings_num

Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e

lines 112–113why, one step back
112
113 def test_tarfile_member(self, tmpdir):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 114–115why, one step back
114 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 back
116

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 117–119why, one step back
117 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 back
120
121 with tarfile.open(tar_obj) as tar:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 122why, one step back
122 member = tar.extractfile("test.txt")

Catch AttributeError in utils.super_len (#5239)David Hothambefore adoption2d2447e

line 123why, one step back
123 assert super_len(member) == 4

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 124–125why, one step back
124
125 def test_super_len_with__len__(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 126why, one step back
126 foo = [1, 2, 3, 4]

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 127–130why, one step back
127 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 back
131 class LenFile:

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 132–137why, one step back
132 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 back
138 foo = StringIO.StringIO("12345")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 139–143why, one step back
139 assert super_len(foo) == 5
140 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 back
144 with open(__file__, "rb") as f:

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 145–155why, one step back
145 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 back
156 "value, expected",
157 (158 ([("key", "val")], [("key", "val")]),159 ((("key", "val"),), [("key", "val")]),160 ({"key": "val"}, [("key", "val")]),161 (None, None),162 ),163 )

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 164–168why, one step back
164 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 back
169 to_key_val_list("string")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 170–173why, one step back
170
171172class TestUnquoteHeaderValue:173 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 174–175why, one step back
174 "value, expected",
175 (

Update README.mdKenneth Reitzbefore adoption537ac3c

line 176why, one step back
176 (None, None),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 177–182why, one step back
177 ("Test", "Test"),
178 ('"Test"', "Test"),179 ('"Test\\\\"', "Test\\"),180 ('"\\\\Comp\\Res"', "\\Comp\\Res"),181 ),182 )

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 183–186why, one step back
183 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 back
187 assert unquote_header_value('"\\\\Comp\\Res"', True) == "\\\\Comp\\Res"

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 188–194why, one step back
188
189190class TestGetEnvironProxies:191 """Ensures that IP addresses are correctly matches with ranges192 in no_proxy variable.193 """194

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 195why, one step back
195 @pytest.fixture(autouse=True, params=["no_proxy", "NO_PROXY"])

Update README.mdKenneth Reitzbefore adoption537ac3c

line 196why, one step back
196 def no_proxy(self, request, monkeypatch):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 197–199why, one step back
197 monkeypatch.setenv(
198 request.param, "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"199 )

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 200–201why, one step back
200
201 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 202–210why, one step back
202 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 211–214why, one step back
211 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 back
215 "url",
216 (217 "http://192.168.1.1:5000/",218 "http://192.168.1.1/",219 "http://www.requests.com/",220 ),221 )

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 222–225why, one step back
222 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 back
226 "url",
227 (228 "http://192.168.1.1:5000/",229 "http://192.168.1.1/",230 "http://www.requests.com/",231 ),232 )

Update README.mdKenneth Reitzbefore adoption537ac3c

line 233why, one step back
233 def test_bypass_no_proxy_keyword(self, url):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 234why, one step back
234 no_proxy = "192.168.1.1,requests.com"

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 235–237why, one step back
235 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 back
238 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 247–249why, one step back
247 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 back
250 monkeypatch.setenv("http_proxy", "http://proxy.example.com:3128/")
251 no_proxy = "192.168.1.1,requests.com"

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 252–256why, one step back
252 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 back
257 assert is_ipv4_address("8.8.8.8")

Update README.mdKenneth Reitzbefore adoption537ac3c

line 258why, one step back
258

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 259why, one step back
259 @pytest.mark.parametrize("value", ("8.8.8.8.8", "localhost.localdomain"))

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 260–265why, one step back
260 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 back
266 assert is_valid_cidr("192.168.1.0/24")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 267–268why, one step back
267
268 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 269–277why, one step back
269 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 278–283why, one step back
278 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 back
284 assert address_in_network("192.168.1.1", "192.168.1.0/24")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 285–286why, one step back
285
286 def test_invalid(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 287why, one step back
287 assert not address_in_network("172.16.0.1", "192.168.1.0/24")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 288–291why, one step back
288
289290class TestGuessFilename:291 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 292–293why, one step back
292 "value",
293 (1, type("Fake", (object,), {"name": 1})()),

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 294–298why, one step back
294 )
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 back
299 "value, expected_type",
300 (301 (b"value", compat.bytes),302 (b"value".decode("utf-8"), compat.str),303 ),304 )

Update README.mdKenneth Reitzbefore adoption537ac3c

line 305why, one step back
305 def test_guess_filename_valid(self, value, expected_type):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 306why, one step back
306 obj = type("Fake", (object,), {"name": value})()

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 307–313why, one step back
307 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 back
314 "path",
315 (316 "/",

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 317–318why, one step back
317 __file__,
318 pytest.__file__,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 319–321why, one step back
319 "/etc/invalid/location",
320 ),321 )

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 322–325why, one step back
322 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 back
326 zipped_py = tmpdir.join("test.zip")
327 with zipfile.ZipFile(zipped_py.strpath, "w") as f:

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 328–330why, one step back
328 f.write(__file__)
329330 _, name = os.path.splitdrive(__file__)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 331why, one step back
331 zipped_path = os.path.join(zipped_py.strpath, name.lstrip(r"\/"))

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 332–337why, one step back
332 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__)337

Fix extract_zipped_paths infinite loop when provided invalid unc path (#5851)Thomas Lambefore adoptiond8829f9

lines 338–341why, one step back
338 def test_invalid_unc_path(self):
339 path = r"\\localhost\invalid\location"340 assert extract_zipped_paths(path) == path341

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 342–344why, one step back
342
343class TestContentEncodingDetection:344 def test_none(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 345why, one step back
345 encodings = get_encodings_from_content("")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 346–348why, one step back
346 assert not len(encodings)
347348 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 349–350why, one step back
349 "content",
350 (

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 351–358why, one step back
351 # HTML5 meta charset attribute
352 '<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 back
359 ),
360 )

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 361–363why, one step back
361 def test_pragmas(self, content):
362 encodings = get_encodings_from_content(content)363 assert len(encodings) == 1

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 364why, one step back
364 assert encodings[0] == "UTF-8"

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 365–366why, one step back
365
366 def test_precedence(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 367why, one step back
367 content = """

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 368–370why, one step back
368 <?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 back
371 """.strip()
372 assert get_encodings_from_content(content) == ["HTML5", "HTML4", "XML"]

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 373–376why, one step back
373
374375class TestGuessJSONUTF:376 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 377–388why, one step back
377 "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 README.mdKenneth Reitzbefore adoption537ac3c

line 389why, one step back
389 def test_encoded(self, encoding):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 390why, one step back
390 data = "{}".encode(encoding)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 391–393why, one step back
391 assert guess_json_utf(data) == encoding
392393 def test_bad_utf_like_encoding(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 394why, one step back
394 assert guess_json_utf(b"\x00\x00\x00\x00") is None

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 395–396why, one step back
395
396 @pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 397–404why, one step back
397 ("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 README.mdKenneth Reitzbefore adoption537ac3c

line 405why, one step back
405 def test_guess_by_bom(self, encoding, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 406why, one step back
406 data = "\ufeff{}".encode(encoding)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 407–410why, one step back
407 assert guess_json_utf(data) == expected
408409410USER = PASSWORD = "%!*'();:@&=+$,/?#[] "

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 411–412why, one step back
411ENCODED_USER = compat.quote(USER, "")
412ENCODED_PASSWORD = compat.quote(PASSWORD, "")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 413–415why, one step back
413
414415@pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 416–417why, one step back
416 "url, auth",
417 (

Update README.mdKenneth Reitzbefore adoption537ac3c

line 418why, one step back
418 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 419–420why, one step back
419 f"http://{ENCODED_USER}:{ENCODED_PASSWORD}@request.com/url.html#test",
420 (USER, PASSWORD),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 421why, one step back
421 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 422why, one step back
422 ("http://user:pass@complex.url.com/path?query=yes", ("user", "pass")),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 423why, one step back
423 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 424–425why, one step back
424 "http://user:pass%20pass@complex.url.com/path?query=yes",
425 ("user", "pass pass"),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 426why, one step back
426 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 427why, one step back
427 ("http://user:pass pass@complex.url.com/path?query=yes", ("user", "pass pass")),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 428why, one step back
428 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 429–430why, one step back
429 "http://user%25user:pass@complex.url.com/path?query=yes",
430 ("user%user", "pass"),

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 431–432why, one step back
431 ),
432 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 433–434why, one step back
433 "http://user:pass%23pass@complex.url.com/path?query=yes",
434 ("user", "pass#pass"),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 435why, one step back
435 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 436–438why, one step back
436 ("http://complex.url.com/path?query=yes", ("", "")),
437 ),438)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 439–443why, one step back
439def 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 back
444 "uri, expected",
445 (

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 446–447why, one step back
446 (
447 # Ensure requoting doesn't break expectations

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 448–449why, one step back
448 "http://example.com/fiz?buz=%25ppicture",
449 "http://example.com/fiz?buz=%25ppicture",

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 450–452why, one step back
450 ),
451 (452 # Ensure we handle unquoted percent signs in redirects

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 453–454why, one step back
453 "http://example.com/fiz?buz=%ppicture",
454 "http://example.com/fiz?buz=%25ppicture",

Update README.mdKenneth Reitzbefore adoption537ac3c

line 455why, one step back
455 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 456–457why, one step back
456 ),
457)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 458–463why, one step back
458def 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 back
464 "uri, expected",
465 (

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 466–467why, one step back
466 (
467 # Illegal bytes

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 468–469why, one step back
468 "http://example.com/?a=%--",
469 "http://example.com/?a=%--",

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 470–472why, one step back
470 ),
471 (472 # Reserved characters

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 473–477why, one step back
473 "http://example.com/?a=%300",
474 "http://example.com/?a=00",475 ),476 ),477)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 478–482why, one step back
478def 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 back
483 "mask, expected",
484 (485 (8, "255.0.0.0"),486 (24, "255.255.255.0"),487 (25, "255.255.255.128"),488 ),489)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 490–493why, one step back
490def test_dotted_netmask(mask, expected):
491 assert dotted_netmask(mask) == expected492493

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 494–506why, one step back
494http_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 README.mdKenneth Reitzbefore adoption537ac3c

lines 507–508why, one step back
507
508

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 509–525why, one step back
509@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 README.mdKenneth Reitzbefore adoption537ac3c

line 526why, one step back
526 # XXX: unsure whether this is reasonable behavior

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 527–529why, one step back
527 ("file:///etc/motd", "socks5://http.proxy", all_proxies),
528 ),529)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 530–535why, one step back
530def 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 back
536 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 542–546why, one step back
542def 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 back
547 "value, expected",
548 (549 ("application/xml", ("application/xml", {})),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 550why, one step back
550 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 551–552why, one step back
551 "application/json ; charset=utf-8",
552 ("application/json", {"charset": "utf-8"}),

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 553–554why, one step back
553 ),
554 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 555–556why, one step back
555 "application/json ; Charset=utf-8",
556 ("application/json", {"charset": "utf-8"}),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 557why, one step back
557 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 558why, one step back
558 ("text/plain", ("text/plain", {})),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 559why, one step back
559 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 560–568why, one step back
560 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 569–570why, one step back
569 ),
570 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 571–579why, one step back
571 '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 README.mdKenneth Reitzbefore adoption537ac3c

lines 580–581why, one step back
580 ),
581 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 582–590why, one step back
582 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 591–593why, one step back
591 ),
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 back
594 (
595 "multipart/form-data",596 {597 "boundary": "something",598 "boundary2": "something_else",599 "no_equals": True,600 },601 ),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 602why, one step back
602 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 603–605why, one step back
603 ("application/json ; ; ", ("application/json", {})),
604 ),605)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 606–610why, one step back
606def 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 back
611 "value, expected",
612 (613 (CaseInsensitiveDict(), None),

Update README.mdKenneth Reitzbefore adoption537ac3c

line 614why, one step back
614 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 615–616why, one step back
615 CaseInsensitiveDict({"content-type": "application/json; charset=utf-8"}),
616 "utf-8",

Update README.mdKenneth Reitzbefore adoption537ac3c

line 617why, one step back
617 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 618–620why, one step back
618 (CaseInsensitiveDict({"content-type": "text/plain"}), "ISO-8859-1"),
619 ),620)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 621–625why, one step back
621def 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 back
626 "value, length",
627 (628 ("", 0),629 ("T", 1),630 ("Test", 4),631 ("Cont", 0),632 ("Other", -5),633 ("Content", None),634 ),635)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 636–644why, one step back
636def 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 back
645 "value, expected",
646 (

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 647–648why, one step back
647 (
648 '<http:/.../front.jpeg>; rel=front; type="image/jpeg"',

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 649why, one step back
649 [{"url": "http:/.../front.jpeg", "rel": "front", "type": "image/jpeg"}],

Update README.mdKenneth Reitzbefore adoption537ac3c

line 650why, one step back
650 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 651–652why, one step back
651 ("<http:/.../front.jpeg>", [{"url": "http:/.../front.jpeg"}]),
652 ("<http:/.../front.jpeg>;", [{"url": "http:/.../front.jpeg"}]),

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 653–655why, one step back
653 (
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 back
656 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
657 {"url": "http://.../back.jpeg"},658 ],

Update README.mdKenneth Reitzbefore adoption537ac3c

line 659why, one step back
659 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 660–662why, one step back
660 ("", []),
661 ),662)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 663–667why, one step back
663def 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 back
668 "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 back
673 (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 674–675why, one step back
674 "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 back
676 ),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 677–679why, one step back
677 ("http://user@example.com/path?query", "http://user@example.com/path?query"),
678 ),679)

Update README.mdKenneth Reitzbefore adoption537ac3c

line 680why, one step back
680def test_prepend_scheme_if_needed(value, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 681why, one step back
681 assert prepend_scheme_if_needed(value, "http") == expected

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 682–684why, one step back
682
683684@pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 685–691why, one step back
685 "value, expected",
686 (687 ("T", "T"),688 (b"T", "T"),689 ("T", "T"),690 ),691)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 692–696why, one step back
692def 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 back
697 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 707–711why, one step back
707def 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 back
712 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 726–729why, one step back
726def 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 back
730 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 README.mdKenneth Reitzbefore adoption537ac3c

lines 738–741why, one step back
738 assert should_bypass_proxies(url, no_proxy=None) == expected
739740741@pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 742–753why, one step back
742 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 754–757why, one step back
754def 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 back
758 proxy_bypass = mocker.patch("requests.utils.proxy_bypass")

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 759–763why, one step back
759 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 back
764 "cookiejar",
765 (

Update README.mdKenneth Reitzbefore adoption537ac3c

line 766why, one step back
766 compat.cookielib.CookieJar(),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 767–769why, one step back
767 RequestsCookieJar(),
768 ),769)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 770–773why, one step back
770def 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 back
774 cookiedict = {"test": "cookies", "good": "cookies"}

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 775–780why, one step back
775 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 back
781 "value, expected",
782 (783 ("test", True),784 ("æíöû", False),785 ("ジェーピーニック", False),786 ),

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 787–792why, one step back
787)
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 back
793 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 806–808why, one step back
806 """Tests for function should_bypass_proxies to check if proxy
807 can be bypassed or not using the 'no_proxy' argument808 """

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 809why, one step back
809 no_proxy = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 810–813why, one step back
810 # Test 'no_proxy' argument
811 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected812813

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 814why, one step back
814@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")

Update README.mdKenneth Reitzbefore adoption537ac3c

line 815why, one step back
815@pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 816–830why, one step back
816 "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 README.mdKenneth Reitzbefore adoption537ac3c

lines 831–834why, one step back
831 """Tests for function should_bypass_proxies to check if proxy
832 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 back
835 override = "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"

Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583

line 836why, one step back
836 import winreg

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 837–849why, one step back
837
838 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 back
850 if value_name == "ProxyEnable":

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 851–853why, one step back
851 # 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 back
854 elif value_name == "ProxyOverride":

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 855–856why, one step back
855 return [override]
856

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 857–863why, one step back
857 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 README.mdKenneth Reitzbefore adoption537ac3c

lines 864–867why, one step back
864 assert should_bypass_proxies(url, None) == expected
865866867@pytest.mark.parametrize(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 868–875why, one step back
868 "env_name, value",
869 (870 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),871 ("no_proxy", None),872 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),873 ("a_new_key", None),874 ),875)

Update README.mdKenneth Reitzbefore adoption537ac3c

lines 876–888why, one step back
876def test_set_environ(env_name, value):
877 """Tests set_environ will set environ values and will restore the environ."""878 environ_copy = copy.deepcopy(os.environ)879 with set_environ(env_name, value):880 assert os.environ.get(env_name) == value881882 assert os.environ == environ_copy883884885def test_set_environ_raises_exception():886 """Tests set_environ will raise exceptions in context when the887 value parameter is None."""888 with pytest.raises(Exception) as exception:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 889–890why, one step back
889 with set_environ("test1", None):
890 raise Exception("Expected exception")

Update README.mdKenneth Reitzbefore adoption537ac3c

line 891why, one step back
891

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 892why, one step back
892 assert "Expected exception" in str(exception.value)