Skip to content
Myr

test_utils.py

This file

Path

tests/test_utils.py

990 lines · 29.9 KiB · Python

Last changed by

Fix malformed value parsing for Content-Type (#7309)Nate Prewittbefore adoptionf0198e6

History of this file

Take it

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 4–6why, one step back
4import tarfile
5import zipfile6from 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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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")

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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])

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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:

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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])

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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:

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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")

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 111–115why, one step back
111 with file_obj.open(mode) as fd:
112 assert super_len(fd) == 4113 assert len(recwarn) == warnings_num114115 def test_tarfile_member(self, tmpdir):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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")

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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")

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 125–127why, one step back
125 assert super_len(member) == 4
126127 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]

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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:

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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")

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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:

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 172why, one step back
172

Fix empty netrc entry usage (#7205)Nate Prewittbefore adoption4791422

lines 173–182why, one step back
173 def test_empty_default_credentials_ignored(self, tmp_path, monkeypatch):
174 """Empty default credentials should not be returned."""175 netrc_path = tmp_path / ".netrc"176 monkeypatch.setenv("NETRC", str(netrc_path))177 with open(netrc_path, "w") as f:178 f.write("machine example.com login user password pass\ndefault\n")179180 auth = get_netrc_auth("http://httpbin.org/")181 assert auth is None182

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 183–185why, one step back
183
184class TestToKeyValList:185 @pytest.mark.parametrize(

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

lines 186–193why, one step back
186 "value, expected",
187 (188 ([("key", "val")], [("key", "val")]),189 ((("key", "val"),), [("key", "val")]),190 ({"key": "val"}, [("key", "val")]),191 (None, None),192 ),193 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 194–198why, one step back
194 def test_valid(self, value, expected):
195 assert to_key_val_list(value) == expected196197 def test_invalid(self):198 with pytest.raises(ValueError):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 200–203why, one step back
200
201202class TestUnquoteHeaderValue:203 @pytest.mark.parametrize(

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

lines 204–205why, one step back
204 "value, expected",
205 (

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

lines 207–212why, one step back
207 ("Test", "Test"),
208 ('"Test"', "Test"),209 ('"Test\\\\"', "Test\\"),210 ('"\\\\Comp\\Res"', "\\Comp\\Res"),211 ),212 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 213–216why, one step back
213 def test_valid(self, value, expected):
214 assert unquote_header_value(value) == expected215216 def test_is_filename(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 218–224why, one step back
218
219220class TestGetEnvironProxies:221 """Ensures that IP addresses are correctly matches with ranges222 in no_proxy variable.223 """224

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

lines 227–229why, one step back
227 monkeypatch.setenv(
228 request.param, "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"229 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 230–231why, one step back
230
231 @pytest.mark.parametrize(

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

lines 232–240why, one step back
232 "url",
233 (234 "http://192.168.0.1:5000/",235 "http://192.168.0.1/",236 "http://172.16.1.1/",237 "http://172.16.1.1:5000/",238 "http://localhost.localdomain:5000/v1.0/",239 ),240 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 241–244why, one step back
241 def test_bypass(self, url):
242 assert get_environ_proxies(url, no_proxy=None) == {}243244 @pytest.mark.parametrize(

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 252–255why, one step back
252 def test_not_bypass(self, url):
253 assert get_environ_proxies(url, no_proxy=None) != {}254255 @pytest.mark.parametrize(

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

lines 256–262why, one step back
256 "url",
257 (258 "http://192.168.1.1:5000/",259 "http://192.168.1.1/",260 "http://www.requests.com/",261 ),262 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 265–267why, one step back
265 assert get_environ_proxies(url, no_proxy=no_proxy) == {}
266267 @pytest.mark.parametrize(

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

lines 268–276why, one step back
268 "url",
269 (270 "http://192.168.0.1:5000/",271 "http://192.168.0.1/",272 "http://172.16.1.1/",273 "http://172.16.1.1:5000/",274 "http://localhost.localdomain:5000/v1.0/",275 ),276 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 277–279why, one step back
277 def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):
278 # This is testing that the 'no_proxy' argument overrides the279 # environment variable 'no_proxy'

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 282–286why, one step back
282 assert get_environ_proxies(url, no_proxy=no_proxy) != {}
283284285class TestIsIPv4Address:286 def test_valid(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 288why, one step back
288

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 290–295why, one step back
290 def test_invalid(self, value):
291 assert not is_ipv4_address(value)292293294class TestIsValidCIDR:295 def test_valid(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 297–298why, one step back
297
298 @pytest.mark.parametrize(

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

lines 299–307why, one step back
299 "value",
300 (301 "8.8.8.8",302 "192.168.1.0/a",303 "192.168.1.0/128",304 "192.168.1.0/-1",305 "192.168.1.999/24",306 ),307 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 308–313why, one step back
308 def test_invalid(self, value):
309 assert not is_valid_cidr(value)310311312class TestAddressInNetwork:313 def test_valid(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 315–316why, one step back
315
316 def test_invalid(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 318–321why, one step back
318
319320class TestGuessFilename:321 @pytest.mark.parametrize(

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 324–328why, one step back
324 )
325 def test_guess_filename_invalid(self, value):326 assert guess_filename(value) is None327328 @pytest.mark.parametrize(

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

lines 329–334why, one step back
329 "value, expected_type",
330 (331 (b"value", compat.bytes),332 (b"value".decode("utf-8"), compat.str),333 ),334 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 337–343why, one step back
337 result = guess_filename(obj)
338 assert result == value339 assert isinstance(result, expected_type)340341342class TestExtractZippedPaths:343 @pytest.mark.parametrize(

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

lines 344–346why, one step back
344 "path",
345 (346 "/",

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 347–348why, one step back
347 __file__,
348 pytest.__file__,

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

lines 349–351why, one step back
349 "/etc/invalid/location",
350 ),351 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 352–355why, one step back
352 def test_unzipped_paths_unchanged(self, path):
353 assert path == extract_zipped_paths(path)354355 def test_zipped_paths_extracted(self, tmpdir):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 358–360why, one step back
358 f.write(__file__)
359360 _, name = os.path.splitdrive(__file__)

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 362–363why, one step back
362 extracted_path = extract_zipped_paths(zipped_path)
363

Cleanup extracted file after extract_zipped_path test (#7305)Nate Prewittbefore adoption389eea5

lines 364–369why, one step back
364 try:
365 assert extracted_path != zipped_path366 assert os.path.exists(extracted_path)367 assert filecmp.cmp(extracted_path, __file__)368 finally:369 os.remove(extracted_path)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 370–377why, one step back
370
371 def test_invalid_unc_path(self):372 path = r"\\localhost\invalid\location"373 assert extract_zipped_paths(path) == path374375376class TestContentEncodingDetection:377 def test_none(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 379–381why, one step back
379 assert not len(encodings)
380381 @pytest.mark.parametrize(

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

lines 382–383why, one step back
382 "content",
383 (

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 384–391why, one step back
384 # HTML5 meta charset attribute
385 '<meta charset="UTF-8">',386 # HTML4 pragma directive387 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',388 # XHTML 1.x served with text/html MIME type389 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',390 # XHTML 1.x served as XML391 '<?xml version="1.0" encoding="UTF-8"?>',

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

lines 392–393why, one step back
392 ),
393 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 394–396why, one step back
394 def test_pragmas(self, content):
395 encodings = get_encodings_from_content(content)396 assert len(encodings) == 1

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 398–399why, one step back
398
399 def test_precedence(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 406–409why, one step back
406
407408class TestGuessJSONUTF:409 @pytest.mark.parametrize(

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

lines 410–421why, one step back
410 "encoding",
411 (412 "utf-32",413 "utf-8-sig",414 "utf-16",415 "utf-8",416 "utf-16-be",417 "utf-16-le",418 "utf-32-be",419 "utf-32-le",420 ),421 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 424–426why, one step back
424 assert guess_json_utf(data) == encoding
425426 def test_bad_utf_like_encoding(self):

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 428–429why, one step back
428
429 @pytest.mark.parametrize(

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

lines 430–437why, one step back
430 ("encoding", "expected"),
431 (432 ("utf-16-be", "utf-16"),433 ("utf-16-le", "utf-16"),434 ("utf-32-be", "utf-32"),435 ("utf-32-le", "utf-32"),436 ),437 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 446–448why, one step back
446
447448@pytest.mark.parametrize(

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

lines 449–450why, one step back
449 "url, auth",
450 (

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 451why, one step back
451 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 454why, one step back
454 ),

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 456why, one step back
456 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 459why, one step back
459 ),

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 461why, one step back
461 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 464–465why, one step back
464 ),
465 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 468why, one step back
468 ),

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

lines 469–471why, one step back
469 ("http://complex.url.com/path?query=yes", ("", "")),
470 ),471)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 472–476why, one step back
472def test_get_auth_from_url(url, auth):
473 assert get_auth_from_url(url) == auth474475476@pytest.mark.parametrize(

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

lines 477–478why, one step back
477 "uri, expected",
478 (

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 483–485why, one step back
483 ),
484 (485 # Ensure we handle unquoted percent signs in redirects

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 488why, one step back
488 ),

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

lines 489–490why, one step back
489 ),
490)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 491–496why, one step back
491def test_requote_uri_with_unquoted_percents(uri, expected):
492 """See: https://github.com/psf/requests/issues/2356"""493 assert requote_uri(uri) == expected494495496@pytest.mark.parametrize(

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

lines 497–498why, one step back
497 "uri, expected",
498 (

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 499–500why, one step back
499 (
500 # Illegal bytes

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 503–505why, one step back
503 ),
504 (505 # Reserved characters

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

lines 506–510why, one step back
506 "http://example.com/?a=%300",
507 "http://example.com/?a=00",508 ),509 ),510)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 511–515why, one step back
511def test_unquote_unreserved(uri, expected):
512 assert unquote_unreserved(uri) == expected513514515@pytest.mark.parametrize(

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

lines 516–522why, one step back
516 "mask, expected",
517 (518 (8, "255.0.0.0"),519 (24, "255.255.255.0"),520 (25, "255.255.255.128"),521 ),522)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 523–526why, one step back
523def test_dotted_netmask(mask, expected):
524 assert dotted_netmask(mask) == expected525526

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

lines 527–539why, one step back
527http_proxies = {
528 "http": "http://http.proxy",529 "http://some.host": "http://some.host.proxy",530}531all_proxies = {532 "all": "socks5://http.proxy",533 "all://some.host": "socks5://some.host.proxy",534}535mixed_proxies = {536 "http": "http://http.proxy",537 "http://some.host": "http://some.host.proxy",538 "all": "socks5://http.proxy",539}

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 540–541why, one step back
540
541

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

lines 542–558why, one step back
542@pytest.mark.parametrize(
543 "url, expected, proxies",544 (545 ("hTTp://u:p@Some.Host/path", "http://some.host.proxy", http_proxies),546 ("hTTp://u:p@Other.Host/path", "http://http.proxy", http_proxies),547 ("hTTp:///path", "http://http.proxy", http_proxies),548 ("hTTps://Other.Host", None, http_proxies),549 ("file:///etc/motd", None, http_proxies),550 ("hTTp://u:p@Some.Host/path", "socks5://some.host.proxy", all_proxies),551 ("hTTp://u:p@Other.Host/path", "socks5://http.proxy", all_proxies),552 ("hTTp:///path", "socks5://http.proxy", all_proxies),553 ("hTTps://Other.Host", "socks5://http.proxy", all_proxies),554 ("http://u:p@other.host/path", "http://http.proxy", mixed_proxies),555 ("http://u:p@some.host/path", "http://some.host.proxy", mixed_proxies),556 ("https://u:p@other.host/path", "socks5://http.proxy", mixed_proxies),557 ("https://u:p@some.host/path", "socks5://http.proxy", mixed_proxies),558 ("https://", "socks5://http.proxy", mixed_proxies),

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

lines 560–562why, one step back
560 ("file:///etc/motd", "socks5://http.proxy", all_proxies),
561 ),562)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 563–568why, one step back
563def test_select_proxies(url, expected, proxies):
564 """Make sure we can select per-host proxies correctly."""565 assert select_proxy(url, proxies) == expected566567568@pytest.mark.parametrize(

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

lines 569–574why, one step back
569 "value, expected",
570 (571 ('foo="is a fish", bar="as well"', {"foo": "is a fish", "bar": "as well"}),572 ("key_without_value", {"key_without_value": None}),573 ),574)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 575–579why, one step back
575def test_parse_dict_header(value, expected):
576 assert parse_dict_header(value) == expected577578579@pytest.mark.parametrize(

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

lines 580–582why, one step back
580 "value, expected",
581 (582 ("application/xml", ("application/xml", {})),

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 583why, one step back
583 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 586–587why, one step back
586 ),
587 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 590why, one step back
590 ),

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 592why, one step back
592 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 611–612why, one step back
611 ),
612 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 621–623why, one step back
621 ),
622 (623 'multipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals ',

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

lines 624–630why, one step back
624 (
625 "multipart/form-data",626 {627 "boundary": "something",628 "boundary2": "something_else",629 },630 ),

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 631why, one step back
631 ),

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

lines 632–634why, one step back
632 ("application/json ; ; ", ("application/json", {})),
633 ),634)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 635–639why, one step back
635def test__parse_content_type_header(value, expected):
636 assert _parse_content_type_header(value) == expected637638639@pytest.mark.parametrize(

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

lines 640–642why, one step back
640 "value, expected",
641 (642 (CaseInsensitiveDict(), None),

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 643why, one step back
643 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 646why, one step back
646 ),

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

line 647why, one step back
647 (CaseInsensitiveDict({"content-type": "text/plain"}), "ISO-8859-1"),

Fix malformed value parsing for Content-Type (#7309)Nate Prewittbefore adoptionf0198e6

lines 648–651why, one step back
648 (
649 CaseInsensitiveDict({"content-type": "text/html; charset"}),650 "ISO-8859-1",651 ),

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

lines 652–653why, one step back
652 ),
653)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 654–658why, one step back
654def test_get_encoding_from_headers(value, expected):
655 assert get_encoding_from_headers(value) == expected656657658@pytest.mark.parametrize(

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

lines 659–668why, one step back
659 "value, length",
660 (661 ("", 0),662 ("T", 1),663 ("Test", 4),664 ("Cont", 0),665 ("Other", -5),666 ("Content", None),667 ),668)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 669–677why, one step back
669def test_iter_slices(value, length):
670 if length is None or (length <= 0 and len(value) > 0):671 # Reads all content at once672 assert len(list(iter_slices(value, length))) == 1673 else:674 assert len(list(iter_slices(value, 1))) == length675676677@pytest.mark.parametrize(

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

lines 678–679why, one step back
678 "value, expected",
679 (

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 683why, one step back
683 ),

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 686–688why, one step back
686 (
687 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',688 [

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

lines 689–691why, one step back
689 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
690 {"url": "http://.../back.jpeg"},691 ],

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 692why, one step back
692 ),

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

lines 693–695why, one step back
693 ("", []),
694 ),695)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 696–700why, one step back
696def test_parse_header_links(value, expected):
697 assert parse_header_links(value) == expected698699700@pytest.mark.parametrize(

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

lines 701–705why, one step back
701 "value, expected",
702 (703 ("example.com/path", "http://example.com/path"),704 ("//example.com/path", "http://example.com/path"),705 ("example.com:80", "http://example.com:80"),

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 706why, one step back
706 (

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 709why, one step back
709 ),

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

lines 710–712why, one step back
710 ("http://user@example.com/path?query", "http://user@example.com/path?query"),
711 ),712)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 715–717why, one step back
715
716717@pytest.mark.parametrize(

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

lines 718–724why, one step back
718 "value, expected",
719 (720 ("T", "T"),721 (b"T", "T"),722 ("T", "T"),723 ),724)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 725–729why, one step back
725def test_to_native_string(value, expected):
726 assert to_native_string(value) == expected727728729@pytest.mark.parametrize(

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

lines 730–739why, one step back
730 "url, expected",
731 (732 ("http://u:p@example.com/path?a=1#test", "http://example.com/path?a=1"),733 ("http://example.com/path", "http://example.com/path"),734 ("//u:p@example.com/path", "//example.com/path"),735 ("//example.com/path", "//example.com/path"),736 ("example.com/path", "//example.com/path"),737 ("scheme:u:p@example.com/path", "scheme://example.com/path"),738 ),739)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 740–744why, one step back
740def test_urldefragauth(url, expected):
741 assert urldefragauth(url) == expected742743744@pytest.mark.parametrize(

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

lines 745–758why, one step back
745 "url, expected",
746 (747 ("http://192.168.0.1:5000/", True),748 ("http://192.168.0.1/", True),749 ("http://172.16.1.1/", True),750 ("http://172.16.1.1:5000/", True),751 ("http://localhost.localdomain:5000/v1.0/", True),752 ("http://google.com:6000/", True),753 ("http://172.16.1.12/", False),754 ("http://172.16.1.12:5000/", False),755 ("http://google.com:5000/v1.0/", False),756 ("file:///some/path/on/disk", True),757 ),758)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 759–762why, one step back
759def test_should_bypass_proxies(url, expected, monkeypatch):
760 """Tests for function should_bypass_proxies to check if proxy761 can be bypassed or not762 """

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

lines 763–770why, one step back
763 monkeypatch.setenv(
764 "no_proxy",765 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",766 )767 monkeypatch.setenv(768 "NO_PROXY",769 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",770 )

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 771–774why, one step back
771 assert should_bypass_proxies(url, no_proxy=None) == expected
772773774@pytest.mark.parametrize(

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

lines 775–786why, one step back
775 "url, expected",
776 (777 ("http://172.16.1.1/", "172.16.1.1"),778 ("http://172.16.1.1:5000/", "172.16.1.1"),779 ("http://user:pass@172.16.1.1", "172.16.1.1"),780 ("http://user:pass@172.16.1.1:5000", "172.16.1.1"),781 ("http://hostname/", "hostname"),782 ("http://hostname:5000/", "hostname"),783 ("http://user:pass@hostname", "hostname"),784 ("http://user:pass@hostname:5000", "hostname"),785 ),786)

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 794–796why, one step back
794
795796@pytest.mark.parametrize(

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

lines 797–798why, one step back
797 "cookiejar",
798 (

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

lines 800–802why, one step back
800 RequestsCookieJar(),
801 ),802)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 803–806why, one step back
803def test_add_dict_to_cookiejar(cookiejar):
804 """Ensure add_dict_to_cookiejar works for805 non-RequestsCookieJar CookieJars806 """

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 808–813why, one step back
808 cj = add_dict_to_cookiejar(cookiejar, cookiedict)
809 cookies = {cookie.name: cookie.value for cookie in cj}810 assert cookiedict == cookies811812813@pytest.mark.parametrize(

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

lines 814–819why, one step back
814 "value, expected",
815 (816 ("test", True),817 ("æíöû", False),818 ("ジェーピーニック", False),819 ),

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 820–825why, one step back
820)
821def test_unicode_is_ascii(value, expected):822 assert unicode_is_ascii(value) is expected823824825@pytest.mark.parametrize(

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

lines 826–838why, one step back
826 "url, expected",
827 (828 ("http://192.168.0.1:5000/", True),829 ("http://192.168.0.1/", True),830 ("http://172.16.1.1/", True),831 ("http://172.16.1.1:5000/", True),832 ("http://localhost.localdomain:5000/v1.0/", True),833 ("http://172.16.1.12/", False),834 ("http://172.16.1.12:5000/", False),835 ("http://google.com:5000/v1.0/", False),836 ),837)838def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 839–841why, one step back
839 """Tests for function should_bypass_proxies to check if proxy
840 can be bypassed or not using the 'no_proxy' argument841 """

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 843–846why, one step back
843 # Test 'no_proxy' argument
844 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected845846

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

lines 849–863why, one step back
849 "url, expected, override",
850 (851 ("http://192.168.0.1:5000/", True, None),852 ("http://192.168.0.1/", True, None),853 ("http://172.16.1.1/", True, None),854 ("http://172.16.1.1:5000/", True, None),855 ("http://localhost.localdomain:5000/v1.0/", True, None),856 ("http://172.16.1.22/", False, None),857 ("http://172.16.1.22:5000/", False, None),858 ("http://google.com:5000/v1.0/", False, None),859 ("http://mylocalhostname:5000/v1.0/", True, "<local>"),860 ("http://192.168.0.1/", False, ""),861 ),862)863def test_should_bypass_proxies_win_registry(url, expected, override, monkeypatch):

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 864–867why, one step back
864 """Tests for function should_bypass_proxies to check if proxy
865 can be bypassed or not with Windows registry settings866 """867 if override is None:

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

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

Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583

line 869why, one step back
869 import winreg

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 870–882why, one step back
870
871 class RegHandle:872 def Close(self):873 pass874875 ie_settings = RegHandle()876 proxyEnableValues = deque([1, "1"])877878 def OpenKey(key, subkey):879 return ie_settings880881 def QueryValueEx(key, value_name):882 if key is ie_settings:

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 888–889why, one step back
888 return [override]
889

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

lines 890–896why, one step back
890 monkeypatch.setenv("http_proxy", "")
891 monkeypatch.setenv("https_proxy", "")892 monkeypatch.setenv("ftp_proxy", "")893 monkeypatch.setenv("no_proxy", "")894 monkeypatch.setenv("NO_PROXY", "")895 monkeypatch.setattr(winreg, "OpenKey", OpenKey)896 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 897–899why, one step back
897 assert should_bypass_proxies(url, None) == expected
898899

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

lines 900–932why, one step back
900@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")
901def test_should_bypass_proxies_win_registry_bad_values(monkeypatch):902 """Tests for function should_bypass_proxies to check if proxy903 can be bypassed or not with Windows invalid registry settings.904 """905 import winreg906907 class RegHandle:908 def Close(self):909 pass910911 ie_settings = RegHandle()912913 def OpenKey(key, subkey):914 return ie_settings915916 def QueryValueEx(key, value_name):917 if key is ie_settings:918 if value_name == "ProxyEnable":919 # Invalid response; Should be an int or int-y value920 return [""]921 elif value_name == "ProxyOverride":922 return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"]923924 monkeypatch.setenv("http_proxy", "")925 monkeypatch.setenv("https_proxy", "")926 monkeypatch.setenv("no_proxy", "")927 monkeypatch.setenv("NO_PROXY", "")928 monkeypatch.setattr(winreg, "OpenKey", OpenKey)929 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)930 assert should_bypass_proxies("http://172.16.1.1/", None) is False931932

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

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

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

lines 934–941why, one step back
934 "env_name, value",
935 (936 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),937 ("no_proxy", None),938 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),939 ("a_new_key", None),940 ),941)

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

lines 942–954why, one step back
942def test_set_environ(env_name, value):
943 """Tests set_environ will set environ values and will restore the environ."""944 environ_copy = copy.deepcopy(os.environ)945 with set_environ(env_name, value):946 assert os.environ.get(env_name) == value947948 assert os.environ == environ_copy949950951def test_set_environ_raises_exception():952 """Tests set_environ will raise exceptions in context when the953 value parameter is None."""954 with pytest.raises(Exception) as exception:

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

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

Merge pull request #6068 from nateprewitt/sess_prox_warnIan Stapleton Cordascobefore adoption5e74954

line 957why, one step back
957

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

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

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

lines 959–990why, one step back
959
960961@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")962def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):963 """Tests for function should_bypass_proxies to check if proxy964 can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.965 """966 import winreg967968 class RegHandle:969 def Close(self):970 pass971972 ie_settings = RegHandle()973974 def OpenKey(key, subkey):975 return ie_settings976977 def QueryValueEx(key, value_name):978 if key is ie_settings:979 if value_name == "ProxyEnable":980 return [1]981 elif value_name == "ProxyOverride":982 return [983 "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"984 ]985986 monkeypatch.setenv("NO_PROXY", "")987 monkeypatch.setenv("no_proxy", "")988 monkeypatch.setattr(winreg, "OpenKey", OpenKey)989 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)990 assert should_bypass_proxies("http://example.com/", None) is False