Skip to content
Myr

test_utils.py

This file

Path

tests/test_utils.py

977 lines · 29.4 KiB · Python

Last changed by

Add more tests to prevent regression of CVE 2024 47081Arthur Woimbéebefore adoption5b4b64c

History of this file

Take it

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 1–2why, one step 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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 8why, one step back
8from unittest import mock

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

line 11why, one step back
11

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 17–25why, one step back
17 _parse_content_type_header,
18 add_dict_to_cookiejar,19 address_in_network,20 dotted_netmask,21 extract_zipped_paths,22 get_auth_from_url,23 get_encoding_from_headers,24 get_encodings_from_content,25 get_environ_proxies,

Add more tests to prevent regression of CVE 2024 47081Arthur Woimbéebefore adoption5b4b64c

line 26why, one step back
26 get_netrc_auth,

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

lines 27–45why, one step back
27 guess_filename,
28 guess_json_utf,29 is_ipv4_address,30 is_valid_cidr,31 iter_slices,32 parse_dict_header,33 parse_header_links,34 prepend_scheme_if_needed,35 requote_uri,36 select_proxy,37 set_environ,38 should_bypass_proxies,39 super_len,40 to_key_val_list,41 to_native_string,42 unquote_header_value,43 unquote_unreserved,44 urldefragauth,45)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 46–51why, one step back
46
47from .compat import StringIO, cStringIO484950class TestSuperLen:51 @pytest.mark.parametrize(

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

lines 52–60why, one step back
52 "stream, value",
53 (54 (StringIO.StringIO, "Test"),55 (BytesIO, b"Test"),56 pytest.param(57 cStringIO, "Test", marks=pytest.mark.skipif("cStringIO is None")58 ),59 ),60 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 61–68why, one step back
61 def test_io_streams(self, stream, value):
62 """Ensures that we properly deal with different kinds of IO streams."""63 assert super_len(stream()) == 064 assert super_len(stream(value)) == 46566 def test_super_len_correctly_calculates_len_of_partially_read_file(self):67 """Ensure that we handle partially consumed file like objects."""68 s = StringIO.StringIO()

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

line 69why, one step back
69 s.write("foobarbogus")

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 70–71why, one step back
70 assert super_len(s) == 0
71

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 73–74why, one step back
73 def test_super_len_handles_files_raising_weird_errors_in_tell(self, error):
74 """If tell() raises errors, assume the cursor is at position zero."""

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

lines 75–76why, one step back
75
76 class BoomFile:

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 77–84why, one step back
77 def __len__(self):
78 return 57980 def tell(self):81 raise error()8283 assert super_len(BoomFile()) == 084

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 86–87why, one step back
86 def test_super_len_tell_ioerror(self, error):
87 """Ensure that if tell gives an IOError super_len doesn't fail"""

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

lines 88–89why, one step back
88
89 class NoLenBoomFile:

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 90–98why, one step back
90 def tell(self):
91 raise error()9293 def seek(self, offset, whence):94 pass9596 assert super_len(NoLenBoomFile()) == 09798 def test_string(self):

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

line 99why, one step back
99 assert super_len("Test") == 4

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 100–101why, one step back
100
101 @pytest.mark.parametrize(

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 114–115why, one step back
114
115 def test_tarfile_member(self, tmpdir):

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

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

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

line 118why, one step back
118

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

lines 119–121why, one step back
119 tar_obj = str(tmpdir.join("test.tar"))
120 with tarfile.open(tar_obj, "w") as tar:121 tar.add(str(file_obj), arcname="test.txt")

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

lines 122–123why, one step back
122
123 with tarfile.open(tar_obj) as tar:

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

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 126–127why, one step back
126
127 def test_super_len_with__len__(self):

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 129–132why, one step back
129 len_foo = super_len(foo)
130 assert len_foo == 4131132 def test_super_len_with_no__len__(self):

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

line 133why, one step back
133 class LenFile:

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 134–139why, one step back
134 def __init__(self):
135 self.len = 5136137 assert super_len(LenFile()) == 5138139 def test_super_len_with_tell(self):

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

line 140why, one step back
140 foo = StringIO.StringIO("12345")

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 141–145why, one step back
141 assert super_len(foo) == 5
142 foo.read(2)143 assert super_len(foo) == 3144145 def test_super_len_with_fileno(self):

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

line 146why, one step back
146 with open(__file__, "rb") as f:

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 147–153why, one step back
147 length = super_len(f)
148 file_data = f.read()149 assert length == len(file_data)150151 def test_super_len_with_no_matches(self):152 """Ensure that objects without any length methods default to 0"""153 assert super_len(object()) == 0

Add more tests to prevent regression of CVE 2024 47081Arthur Woimbéebefore adoption5b4b64c

lines 154–171why, one step back
154
155156class TestGetNetrcAuth:157 def test_works(self, tmp_path, monkeypatch):158 netrc_path = tmp_path / ".netrc"159 monkeypatch.setenv("NETRC", str(netrc_path))160 with open(netrc_path, "w") as f:161 f.write("machine example.com login aaaa password bbbb\n")162 auth = get_netrc_auth("http://example.com/thing")163 assert auth == ("aaaa", "bbbb")164165 def test_not_vulnerable_to_bad_url_parsing(self, tmp_path, monkeypatch):166 netrc_path = tmp_path / ".netrc"167 monkeypatch.setenv("NETRC", str(netrc_path))168 with open(netrc_path, "w") as f:169 f.write("machine example.com login aaaa password bbbb\n")170 auth = get_netrc_auth("http://example.com:@evil.com/'")171 assert auth is None

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 172–175why, one step back
172
173174class TestToKeyValList:175 @pytest.mark.parametrize(

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

lines 176–183why, one step back
176 "value, expected",
177 (178 ([("key", "val")], [("key", "val")]),179 ((("key", "val"),), [("key", "val")]),180 ({"key": "val"}, [("key", "val")]),181 (None, None),182 ),183 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 184–188why, one step back
184 def test_valid(self, value, expected):
185 assert to_key_val_list(value) == expected186187 def test_invalid(self):188 with pytest.raises(ValueError):

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

line 189why, one step back
189 to_key_val_list("string")

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 190–193why, one step back
190
191192class TestUnquoteHeaderValue:193 @pytest.mark.parametrize(

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

lines 194–195why, one step back
194 "value, expected",
195 (

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 197–202why, one step back
197 ("Test", "Test"),
198 ('"Test"', "Test"),199 ('"Test\\\\"', "Test\\"),200 ('"\\\\Comp\\Res"', "\\Comp\\Res"),201 ),202 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 203–206why, one step back
203 def test_valid(self, value, expected):
204 assert unquote_header_value(value) == expected205206 def test_is_filename(self):

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

line 207why, one step back
207 assert unquote_header_value('"\\\\Comp\\Res"', True) == "\\\\Comp\\Res"

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 208–214why, one step back
208
209210class TestGetEnvironProxies:211 """Ensures that IP addresses are correctly matches with ranges212 in no_proxy variable.213 """214

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 217–219why, one step back
217 monkeypatch.setenv(
218 request.param, "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"219 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 220–221why, one step back
220
221 @pytest.mark.parametrize(

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

lines 222–230why, one step back
222 "url",
223 (224 "http://192.168.0.1:5000/",225 "http://192.168.0.1/",226 "http://172.16.1.1/",227 "http://172.16.1.1:5000/",228 "http://localhost.localdomain:5000/v1.0/",229 ),230 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 231–234why, one step back
231 def test_bypass(self, url):
232 assert get_environ_proxies(url, no_proxy=None) == {}233234 @pytest.mark.parametrize(

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

lines 235–241why, one step back
235 "url",
236 (237 "http://192.168.1.1:5000/",238 "http://192.168.1.1/",239 "http://www.requests.com/",240 ),241 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 242–245why, one step back
242 def test_not_bypass(self, url):
243 assert get_environ_proxies(url, no_proxy=None) != {}244245 @pytest.mark.parametrize(

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

lines 246–252why, one step back
246 "url",
247 (248 "http://192.168.1.1:5000/",249 "http://192.168.1.1/",250 "http://www.requests.com/",251 ),252 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 255–257why, one step back
255 assert get_environ_proxies(url, no_proxy=no_proxy) == {}
256257 @pytest.mark.parametrize(

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

lines 258–266why, one step back
258 "url",
259 (260 "http://192.168.0.1:5000/",261 "http://192.168.0.1/",262 "http://172.16.1.1/",263 "http://172.16.1.1:5000/",264 "http://localhost.localdomain:5000/v1.0/",265 ),266 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 267–269why, one step back
267 def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):
268 # This is testing that the 'no_proxy' argument overrides the269 # environment variable 'no_proxy'

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

lines 270–271why, one step back
270 monkeypatch.setenv("http_proxy", "http://proxy.example.com:3128/")
271 no_proxy = "192.168.1.1,requests.com"

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 272–276why, one step back
272 assert get_environ_proxies(url, no_proxy=no_proxy) != {}
273274275class TestIsIPv4Address:276 def test_valid(self):

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

line 277why, one step back
277 assert is_ipv4_address("8.8.8.8")

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 278why, one step back
278

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 280–285why, one step back
280 def test_invalid(self, value):
281 assert not is_ipv4_address(value)282283284class TestIsValidCIDR:285 def test_valid(self):

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

line 286why, one step back
286 assert is_valid_cidr("192.168.1.0/24")

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 287–288why, one step back
287
288 @pytest.mark.parametrize(

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

lines 289–297why, one step back
289 "value",
290 (291 "8.8.8.8",292 "192.168.1.0/a",293 "192.168.1.0/128",294 "192.168.1.0/-1",295 "192.168.1.999/24",296 ),297 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 298–303why, one step back
298 def test_invalid(self, value):
299 assert not is_valid_cidr(value)300301302class TestAddressInNetwork:303 def test_valid(self):

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

line 304why, one step back
304 assert address_in_network("192.168.1.1", "192.168.1.0/24")

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 305–306why, one step back
305
306 def test_invalid(self):

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 308–311why, one step back
308
309310class TestGuessFilename:311 @pytest.mark.parametrize(

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 314–318why, one step back
314 )
315 def test_guess_filename_invalid(self, value):316 assert guess_filename(value) is None317318 @pytest.mark.parametrize(

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

lines 319–324why, one step back
319 "value, expected_type",
320 (321 (b"value", compat.bytes),322 (b"value".decode("utf-8"), compat.str),323 ),324 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 327–333why, one step back
327 result = guess_filename(obj)
328 assert result == value329 assert isinstance(result, expected_type)330331332class TestExtractZippedPaths:333 @pytest.mark.parametrize(

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

lines 334–336why, one step back
334 "path",
335 (336 "/",

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 337–338why, one step back
337 __file__,
338 pytest.__file__,

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

lines 339–341why, one step back
339 "/etc/invalid/location",
340 ),341 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 342–345why, one step back
342 def test_unzipped_paths_unchanged(self, path):
343 assert path == extract_zipped_paths(path)344345 def test_zipped_paths_extracted(self, tmpdir):

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

lines 346–347why, one step back
346 zipped_py = tmpdir.join("test.zip")
347 with zipfile.ZipFile(zipped_py.strpath, "w") as f:

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 348–350why, one step back
348 f.write(__file__)
349350 _, name = os.path.splitdrive(__file__)

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 352–364why, one step back
352 extracted_path = extract_zipped_paths(zipped_path)
353354 assert extracted_path != zipped_path355 assert os.path.exists(extracted_path)356 assert filecmp.cmp(extracted_path, __file__)357358 def test_invalid_unc_path(self):359 path = r"\\localhost\invalid\location"360 assert extract_zipped_paths(path) == path361362363class TestContentEncodingDetection:364 def test_none(self):

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 366–368why, one step back
366 assert not len(encodings)
367368 @pytest.mark.parametrize(

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

lines 369–370why, one step back
369 "content",
370 (

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 371–378why, one step back
371 # HTML5 meta charset attribute
372 '<meta charset="UTF-8">',373 # HTML4 pragma directive374 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',375 # XHTML 1.x served with text/html MIME type376 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',377 # XHTML 1.x served as XML378 '<?xml version="1.0" encoding="UTF-8"?>',

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

lines 379–380why, one step back
379 ),
380 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 381–383why, one step back
381 def test_pragmas(self, content):
382 encodings = get_encodings_from_content(content)383 assert len(encodings) == 1

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 385–386why, one step back
385
386 def test_precedence(self):

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 388–390why, one step back
388 <?xml version="1.0" encoding="XML"?>
389 <meta charset="HTML5">390 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />

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

lines 391–392why, one step back
391 """.strip()
392 assert get_encodings_from_content(content) == ["HTML5", "HTML4", "XML"]

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 393–396why, one step back
393
394395class TestGuessJSONUTF:396 @pytest.mark.parametrize(

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

lines 397–408why, one step back
397 "encoding",
398 (399 "utf-32",400 "utf-8-sig",401 "utf-16",402 "utf-8",403 "utf-16-be",404 "utf-16-le",405 "utf-32-be",406 "utf-32-le",407 ),408 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 411–413why, one step back
411 assert guess_json_utf(data) == encoding
412413 def test_bad_utf_like_encoding(self):

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 417–424why, one step back
417 ("encoding", "expected"),
418 (419 ("utf-16-be", "utf-16"),420 ("utf-16-le", "utf-16"),421 ("utf-32-be", "utf-32"),422 ("utf-32-le", "utf-32"),423 ),424 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 433–435why, one step back
433
434435@pytest.mark.parametrize(

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

lines 436–437why, one step back
436 "url, auth",
437 (

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 438why, one step back
438 (

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 441why, one step back
441 ),

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 443why, one step back
443 (

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 446why, one step back
446 ),

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 448why, one step back
448 (

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 451–452why, one step back
451 ),
452 (

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 455why, one step back
455 ),

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

lines 456–458why, one step back
456 ("http://complex.url.com/path?query=yes", ("", "")),
457 ),458)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 459–463why, one step back
459def test_get_auth_from_url(url, auth):
460 assert get_auth_from_url(url) == auth461462463@pytest.mark.parametrize(

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

lines 464–465why, one step back
464 "uri, expected",
465 (

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 470–472why, one step back
470 ),
471 (472 # Ensure we handle unquoted percent signs in redirects

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 475why, one step back
475 ),

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

lines 476–477why, one step back
476 ),
477)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 478–483why, one step back
478def test_requote_uri_with_unquoted_percents(uri, expected):
479 """See: https://github.com/psf/requests/issues/2356"""480 assert requote_uri(uri) == expected481482483@pytest.mark.parametrize(

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

lines 484–485why, one step back
484 "uri, expected",
485 (

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 486–487why, one step back
486 (
487 # Illegal bytes

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 490–492why, one step back
490 ),
491 (492 # Reserved characters

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

lines 493–497why, one step back
493 "http://example.com/?a=%300",
494 "http://example.com/?a=00",495 ),496 ),497)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 498–502why, one step back
498def test_unquote_unreserved(uri, expected):
499 assert unquote_unreserved(uri) == expected500501502@pytest.mark.parametrize(

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

lines 503–509why, one step back
503 "mask, expected",
504 (505 (8, "255.0.0.0"),506 (24, "255.255.255.0"),507 (25, "255.255.255.128"),508 ),509)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 510–513why, one step back
510def test_dotted_netmask(mask, expected):
511 assert dotted_netmask(mask) == expected512513

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

lines 514–526why, one step back
514http_proxies = {
515 "http": "http://http.proxy",516 "http://some.host": "http://some.host.proxy",517}518all_proxies = {519 "all": "socks5://http.proxy",520 "all://some.host": "socks5://some.host.proxy",521}522mixed_proxies = {523 "http": "http://http.proxy",524 "http://some.host": "http://some.host.proxy",525 "all": "socks5://http.proxy",526}

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 527–528why, one step back
527
528

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

lines 529–545why, one step back
529@pytest.mark.parametrize(
530 "url, expected, proxies",531 (532 ("hTTp://u:p@Some.Host/path", "http://some.host.proxy", http_proxies),533 ("hTTp://u:p@Other.Host/path", "http://http.proxy", http_proxies),534 ("hTTp:///path", "http://http.proxy", http_proxies),535 ("hTTps://Other.Host", None, http_proxies),536 ("file:///etc/motd", None, http_proxies),537 ("hTTp://u:p@Some.Host/path", "socks5://some.host.proxy", all_proxies),538 ("hTTp://u:p@Other.Host/path", "socks5://http.proxy", all_proxies),539 ("hTTp:///path", "socks5://http.proxy", all_proxies),540 ("hTTps://Other.Host", "socks5://http.proxy", all_proxies),541 ("http://u:p@other.host/path", "http://http.proxy", mixed_proxies),542 ("http://u:p@some.host/path", "http://some.host.proxy", mixed_proxies),543 ("https://u:p@other.host/path", "socks5://http.proxy", mixed_proxies),544 ("https://u:p@some.host/path", "socks5://http.proxy", mixed_proxies),545 ("https://", "socks5://http.proxy", mixed_proxies),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 547–549why, one step back
547 ("file:///etc/motd", "socks5://http.proxy", all_proxies),
548 ),549)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 550–555why, one step back
550def test_select_proxies(url, expected, proxies):
551 """Make sure we can select per-host proxies correctly."""552 assert select_proxy(url, proxies) == expected553554555@pytest.mark.parametrize(

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

lines 556–561why, one step back
556 "value, expected",
557 (558 ('foo="is a fish", bar="as well"', {"foo": "is a fish", "bar": "as well"}),559 ("key_without_value", {"key_without_value": None}),560 ),561)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 562–566why, one step back
562def test_parse_dict_header(value, expected):
563 assert parse_dict_header(value) == expected564565566@pytest.mark.parametrize(

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

lines 567–569why, one step back
567 "value, expected",
568 (569 ("application/xml", ("application/xml", {})),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 570why, one step back
570 (

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 573–574why, one step back
573 ),
574 (

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 577why, one step back
577 ),

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 579why, one step back
579 (

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

lines 580–588why, one step back
580 "multipart/form-data; boundary = something ; boundary2='something_else' ; no_equals ",
581 (582 "multipart/form-data",583 {584 "boundary": "something",585 "boundary2": "something_else",586 "no_equals": True,587 },588 ),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 589–590why, one step back
589 ),
590 (

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

lines 591–599why, one step back
591 'multipart/form-data; boundary = something ; boundary2="something_else" ; no_equals ',
592 (593 "multipart/form-data",594 {595 "boundary": "something",596 "boundary2": "something_else",597 "no_equals": True,598 },599 ),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 600–601why, one step back
600 ),
601 (

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

lines 602–610why, one step back
602 "multipart/form-data; boundary = something ; 'boundary2=something_else' ; no_equals ",
603 (604 "multipart/form-data",605 {606 "boundary": "something",607 "boundary2": "something_else",608 "no_equals": True,609 },610 ),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 611–613why, one step back
611 ),
612 (613 'multipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals ',

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

lines 614–621why, one step back
614 (
615 "multipart/form-data",616 {617 "boundary": "something",618 "boundary2": "something_else",619 "no_equals": True,620 },621 ),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 622why, one step back
622 ),

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

lines 623–625why, one step back
623 ("application/json ; ; ", ("application/json", {})),
624 ),625)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 626–630why, one step back
626def test__parse_content_type_header(value, expected):
627 assert _parse_content_type_header(value) == expected628629630@pytest.mark.parametrize(

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

lines 631–633why, one step back
631 "value, expected",
632 (633 (CaseInsensitiveDict(), None),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 634why, one step back
634 (

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 637why, one step back
637 ),

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

lines 638–640why, one step back
638 (CaseInsensitiveDict({"content-type": "text/plain"}), "ISO-8859-1"),
639 ),640)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 641–645why, one step back
641def test_get_encoding_from_headers(value, expected):
642 assert get_encoding_from_headers(value) == expected643644645@pytest.mark.parametrize(

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

lines 646–655why, one step back
646 "value, length",
647 (648 ("", 0),649 ("T", 1),650 ("Test", 4),651 ("Cont", 0),652 ("Other", -5),653 ("Content", None),654 ),655)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 656–664why, one step back
656def test_iter_slices(value, length):
657 if length is None or (length <= 0 and len(value) > 0):658 # Reads all content at once659 assert len(list(iter_slices(value, length))) == 1660 else:661 assert len(list(iter_slices(value, 1))) == length662663664@pytest.mark.parametrize(

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

lines 665–666why, one step back
665 "value, expected",
666 (

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 670why, one step back
670 ),

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 673–675why, one step back
673 (
674 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',675 [

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

lines 676–678why, one step back
676 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
677 {"url": "http://.../back.jpeg"},678 ],

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 679why, one step back
679 ),

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

lines 680–682why, one step back
680 ("", []),
681 ),682)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 683–687why, one step back
683def test_parse_header_links(value, expected):
684 assert parse_header_links(value) == expected685686687@pytest.mark.parametrize(

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

lines 688–692why, one step back
688 "value, expected",
689 (690 ("example.com/path", "http://example.com/path"),691 ("//example.com/path", "http://example.com/path"),692 ("example.com:80", "http://example.com:80"),

Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724

line 693why, one step back
693 (

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

lines 694–695why, one step back
694 "http://user:pass@example.com/path?query",
695 "http://user:pass@example.com/path?query",

Merge pull request #6028 from nateprewitt/prox_auth_fixIan Stapleton Cordascobefore adoption8fa9724

line 696why, one step back
696 ),

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

lines 697–699why, one step back
697 ("http://user@example.com/path?query", "http://user@example.com/path?query"),
698 ),699)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 702–704why, one step back
702
703704@pytest.mark.parametrize(

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

lines 705–711why, one step back
705 "value, expected",
706 (707 ("T", "T"),708 (b"T", "T"),709 ("T", "T"),710 ),711)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 712–716why, one step back
712def test_to_native_string(value, expected):
713 assert to_native_string(value) == expected714715716@pytest.mark.parametrize(

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

lines 717–726why, one step back
717 "url, expected",
718 (719 ("http://u:p@example.com/path?a=1#test", "http://example.com/path?a=1"),720 ("http://example.com/path", "http://example.com/path"),721 ("//u:p@example.com/path", "//example.com/path"),722 ("//example.com/path", "//example.com/path"),723 ("example.com/path", "//example.com/path"),724 ("scheme:u:p@example.com/path", "scheme://example.com/path"),725 ),726)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 727–731why, one step back
727def test_urldefragauth(url, expected):
728 assert urldefragauth(url) == expected729730731@pytest.mark.parametrize(

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

lines 732–745why, one step back
732 "url, expected",
733 (734 ("http://192.168.0.1:5000/", True),735 ("http://192.168.0.1/", True),736 ("http://172.16.1.1/", True),737 ("http://172.16.1.1:5000/", True),738 ("http://localhost.localdomain:5000/v1.0/", True),739 ("http://google.com:6000/", True),740 ("http://172.16.1.12/", False),741 ("http://172.16.1.12:5000/", False),742 ("http://google.com:5000/v1.0/", False),743 ("file:///some/path/on/disk", True),744 ),745)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 746–749why, one step back
746def test_should_bypass_proxies(url, expected, monkeypatch):
747 """Tests for function should_bypass_proxies to check if proxy748 can be bypassed or not749 """

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

lines 750–757why, one step back
750 monkeypatch.setenv(
751 "no_proxy",752 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",753 )754 monkeypatch.setenv(755 "NO_PROXY",756 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",757 )

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 758–761why, one step back
758 assert should_bypass_proxies(url, no_proxy=None) == expected
759760761@pytest.mark.parametrize(

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

lines 762–773why, one step back
762 "url, expected",
763 (764 ("http://172.16.1.1/", "172.16.1.1"),765 ("http://172.16.1.1:5000/", "172.16.1.1"),766 ("http://user:pass@172.16.1.1", "172.16.1.1"),767 ("http://user:pass@172.16.1.1:5000", "172.16.1.1"),768 ("http://hostname/", "hostname"),769 ("http://hostname:5000/", "hostname"),770 ("http://user:pass@hostname", "hostname"),771 ("http://user:pass@hostname:5000", "hostname"),772 ),773)

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 774why, one step back
774def test_should_bypass_proxies_pass_only_hostname(url, expected):

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 775–777why, one step back
775 """The proxy_bypass function should be called with a hostname or IP without
776 a port number or auth credentials.777 """

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

lines 778–780why, one step back
778 with mock.patch("requests.utils.proxy_bypass") as proxy_bypass:
779 should_bypass_proxies(url, no_proxy=None)780 proxy_bypass.assert_called_once_with(expected)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 781–783why, one step back
781
782783@pytest.mark.parametrize(

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

lines 784–785why, one step back
784 "cookiejar",
785 (

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 787–789why, one step back
787 RequestsCookieJar(),
788 ),789)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 790–793why, one step back
790def test_add_dict_to_cookiejar(cookiejar):
791 """Ensure add_dict_to_cookiejar works for792 non-RequestsCookieJar CookieJars793 """

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

line 794why, one step back
794 cookiedict = {"test": "cookies", "good": "cookies"}

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 795–800why, one step back
795 cj = add_dict_to_cookiejar(cookiejar, cookiedict)
796 cookies = {cookie.name: cookie.value for cookie in cj}797 assert cookiedict == cookies798799800@pytest.mark.parametrize(

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

lines 801–806why, one step back
801 "value, expected",
802 (803 ("test", True),804 ("æíöû", False),805 ("ジェーピーニック", False),806 ),

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 807–812why, one step back
807)
808def test_unicode_is_ascii(value, expected):809 assert unicode_is_ascii(value) is expected810811812@pytest.mark.parametrize(

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

lines 813–825why, one step back
813 "url, expected",
814 (815 ("http://192.168.0.1:5000/", True),816 ("http://192.168.0.1/", True),817 ("http://172.16.1.1/", True),818 ("http://172.16.1.1:5000/", True),819 ("http://localhost.localdomain:5000/v1.0/", True),820 ("http://172.16.1.12/", False),821 ("http://172.16.1.12:5000/", False),822 ("http://google.com:5000/v1.0/", False),823 ),824)825def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 826–828why, one step back
826 """Tests for function should_bypass_proxies to check if proxy
827 can be bypassed or not using the 'no_proxy' argument828 """

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 830–833why, one step back
830 # Test 'no_proxy' argument
831 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected832833

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 836–850why, one step back
836 "url, expected, override",
837 (838 ("http://192.168.0.1:5000/", True, None),839 ("http://192.168.0.1/", True, None),840 ("http://172.16.1.1/", True, None),841 ("http://172.16.1.1:5000/", True, None),842 ("http://localhost.localdomain:5000/v1.0/", True, None),843 ("http://172.16.1.22/", False, None),844 ("http://172.16.1.22:5000/", False, None),845 ("http://google.com:5000/v1.0/", False, None),846 ("http://mylocalhostname:5000/v1.0/", True, "<local>"),847 ("http://192.168.0.1/", False, ""),848 ),849)850def test_should_bypass_proxies_win_registry(url, expected, override, monkeypatch):

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 851–854why, one step back
851 """Tests for function should_bypass_proxies to check if proxy
852 can be bypassed or not with Windows registry settings853 """854 if override is None:

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

line 855why, one step back
855 override = "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"

Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583

line 856why, one step back
856 import winreg

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 857–869why, one step back
857
858 class RegHandle:859 def Close(self):860 pass861862 ie_settings = RegHandle()863 proxyEnableValues = deque([1, "1"])864865 def OpenKey(key, subkey):866 return ie_settings867868 def QueryValueEx(key, value_name):869 if key is ie_settings:

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

line 870why, one step back
870 if value_name == "ProxyEnable":

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 871–873why, one step back
871 # this could be a string (REG_SZ) or a 32-bit number (REG_DWORD)
872 proxyEnableValues.rotate()873 return [proxyEnableValues[0]]

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

line 874why, one step back
874 elif value_name == "ProxyOverride":

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 875–876why, one step back
875 return [override]
876

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

lines 877–883why, one step back
877 monkeypatch.setenv("http_proxy", "")
878 monkeypatch.setenv("https_proxy", "")879 monkeypatch.setenv("ftp_proxy", "")880 monkeypatch.setenv("no_proxy", "")881 monkeypatch.setenv("NO_PROXY", "")882 monkeypatch.setattr(winreg, "OpenKey", OpenKey)883 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 884–886why, one step back
884 assert should_bypass_proxies(url, None) == expected
885886

Tolerate bad registry entries in Windows proxy settings (#6149)Nate Prewittbefore adoption210095f

lines 887–919why, one step back
887@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")
888def test_should_bypass_proxies_win_registry_bad_values(monkeypatch):889 """Tests for function should_bypass_proxies to check if proxy890 can be bypassed or not with Windows invalid registry settings.891 """892 import winreg893894 class RegHandle:895 def Close(self):896 pass897898 ie_settings = RegHandle()899900 def OpenKey(key, subkey):901 return ie_settings902903 def QueryValueEx(key, value_name):904 if key is ie_settings:905 if value_name == "ProxyEnable":906 # Invalid response; Should be an int or int-y value907 return [""]908 elif value_name == "ProxyOverride":909 return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"]910911 monkeypatch.setenv("http_proxy", "")912 monkeypatch.setenv("https_proxy", "")913 monkeypatch.setenv("no_proxy", "")914 monkeypatch.setenv("NO_PROXY", "")915 monkeypatch.setattr(winreg, "OpenKey", OpenKey)916 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)917 assert should_bypass_proxies("http://172.16.1.1/", None) is False918919

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

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

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

lines 921–928why, one step back
921 "env_name, value",
922 (923 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),924 ("no_proxy", None),925 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),926 ("a_new_key", None),927 ),928)

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

lines 929–941why, one step back
929def test_set_environ(env_name, value):
930 """Tests set_environ will set environ values and will restore the environ."""931 environ_copy = copy.deepcopy(os.environ)932 with set_environ(env_name, value):933 assert os.environ.get(env_name) == value934935 assert os.environ == environ_copy936937938def test_set_environ_raises_exception():939 """Tests set_environ will raise exceptions in context when the940 value parameter is None."""941 with pytest.raises(Exception) as exception:

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

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

Time out requests' tests after 10 minutes. (#5916)Ben Li-Sauerwinebefore adoptionaae7801

line 944why, one step back
944

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

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

Merge pull request #6302 from flysee/mainIan Stapleton Cordascobefore adoption8dd3b26

lines 946–977why, one step back
946
947948@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")949def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):950 """Tests for function should_bypass_proxies to check if proxy951 can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.952 """953 import winreg954955 class RegHandle:956 def Close(self):957 pass958959 ie_settings = RegHandle()960961 def OpenKey(key, subkey):962 return ie_settings963964 def QueryValueEx(key, value_name):965 if key is ie_settings:966 if value_name == "ProxyEnable":967 return [1]968 elif value_name == "ProxyOverride":969 return [970 "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"971 ]972973 monkeypatch.setenv("NO_PROXY", "")974 monkeypatch.setenv("no_proxy", "")975 monkeypatch.setattr(winreg, "OpenKey", OpenKey)976 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)977 assert should_bypass_proxies("http://example.com/", None) is False