Skip to content
Myr

test_utils.py

This file

Path

tests/test_utils.py

958 lines · 28.7 KiB · Python

Last changed by

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

History of this file

Take it

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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–44why, 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,26 guess_filename,27 guess_json_utf,28 is_ipv4_address,29 is_valid_cidr,30 iter_slices,31 parse_dict_header,32 parse_header_links,33 prepend_scheme_if_needed,34 requote_uri,35 select_proxy,36 set_environ,37 should_bypass_proxies,38 super_len,39 to_key_val_list,40 to_native_string,41 unquote_header_value,42 unquote_unreserved,43 urldefragauth,44)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 45–50why, one step back
45
46from .compat import StringIO, cStringIO474849class TestSuperLen:50 @pytest.mark.parametrize(

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 76–83why, one step back
76 def __len__(self):
77 return 57879 def tell(self):80 raise error()8182 assert super_len(BoomFile()) == 083

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 89–97why, one step back
89 def tell(self):
90 raise error()9192 def seek(self, offset, whence):93 pass9495 assert super_len(NoLenBoomFile()) == 09697 def test_string(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

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

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

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

line 117why, one step back
117

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

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

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

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

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

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 128–131why, one step back
128 len_foo = super_len(foo)
129 assert len_foo == 4130131 def test_super_len_with_no__len__(self):

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

line 132why, one step back
132 class LenFile:

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 133–138why, one step back
133 def __init__(self):
134 self.len = 5135136 assert super_len(LenFile()) == 5137138 def test_super_len_with_tell(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 140–144why, one step back
140 assert super_len(foo) == 5
141 foo.read(2)142 assert super_len(foo) == 3143144 def test_super_len_with_fileno(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 146–156why, one step back
146 length = super_len(f)
147 file_data = f.read()148 assert length == len(file_data)149150 def test_super_len_with_no_matches(self):151 """Ensure that objects without any length methods default to 0"""152 assert super_len(object()) == 0153154155class TestToKeyValList:156 @pytest.mark.parametrize(

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

lines 157–164why, one step back
157 "value, expected",
158 (159 ([("key", "val")], [("key", "val")]),160 ((("key", "val"),), [("key", "val")]),161 ({"key": "val"}, [("key", "val")]),162 (None, None),163 ),164 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 165–169why, one step back
165 def test_valid(self, value, expected):
166 assert to_key_val_list(value) == expected167168 def test_invalid(self):169 with pytest.raises(ValueError):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 171–174why, one step back
171
172173class TestUnquoteHeaderValue:174 @pytest.mark.parametrize(

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 184–187why, one step back
184 def test_valid(self, value, expected):
185 assert unquote_header_value(value) == expected186187 def test_is_filename(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 189–195why, one step back
189
190191class TestGetEnvironProxies:192 """Ensures that IP addresses are correctly matches with ranges193 in no_proxy variable.194 """195

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

lines 203–211why, one step back
203 "url",
204 (205 "http://192.168.0.1:5000/",206 "http://192.168.0.1/",207 "http://172.16.1.1/",208 "http://172.16.1.1:5000/",209 "http://localhost.localdomain:5000/v1.0/",210 ),211 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 212–215why, one step back
212 def test_bypass(self, url):
213 assert get_environ_proxies(url, no_proxy=None) == {}214215 @pytest.mark.parametrize(

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

lines 216–222why, one step back
216 "url",
217 (218 "http://192.168.1.1:5000/",219 "http://192.168.1.1/",220 "http://www.requests.com/",221 ),222 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 223–226why, one step back
223 def test_not_bypass(self, url):
224 assert get_environ_proxies(url, no_proxy=None) != {}225226 @pytest.mark.parametrize(

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

lines 227–233why, one step back
227 "url",
228 (229 "http://192.168.1.1:5000/",230 "http://192.168.1.1/",231 "http://www.requests.com/",232 ),233 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 236–238why, one step back
236 assert get_environ_proxies(url, no_proxy=no_proxy) == {}
237238 @pytest.mark.parametrize(

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

lines 239–247why, one step back
239 "url",
240 (241 "http://192.168.0.1:5000/",242 "http://192.168.0.1/",243 "http://172.16.1.1/",244 "http://172.16.1.1:5000/",245 "http://localhost.localdomain:5000/v1.0/",246 ),247 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 248–250why, one step back
248 def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):
249 # This is testing that the 'no_proxy' argument overrides the250 # environment variable 'no_proxy'

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 253–257why, one step back
253 assert get_environ_proxies(url, no_proxy=no_proxy) != {}
254255256class TestIsIPv4Address:257 def test_valid(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 259why, one step back
259

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 261–266why, one step back
261 def test_invalid(self, value):
262 assert not is_ipv4_address(value)263264265class TestIsValidCIDR:266 def test_valid(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

lines 270–278why, one step back
270 "value",
271 (272 "8.8.8.8",273 "192.168.1.0/a",274 "192.168.1.0/128",275 "192.168.1.0/-1",276 "192.168.1.999/24",277 ),278 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 279–284why, one step back
279 def test_invalid(self, value):
280 assert not is_valid_cidr(value)281282283class TestAddressInNetwork:284 def test_valid(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 289–292why, one step back
289
290291class TestGuessFilename:292 @pytest.mark.parametrize(

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 295–299why, one step back
295 )
296 def test_guess_filename_invalid(self, value):297 assert guess_filename(value) is None298299 @pytest.mark.parametrize(

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

lines 300–305why, one step back
300 "value, expected_type",
301 (302 (b"value", compat.bytes),303 (b"value".decode("utf-8"), compat.str),304 ),305 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 308–314why, one step back
308 result = guess_filename(obj)
309 assert result == value310 assert isinstance(result, expected_type)311312313class TestExtractZippedPaths:314 @pytest.mark.parametrize(

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

lines 315–317why, one step back
315 "path",
316 (317 "/",

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 323–326why, one step back
323 def test_unzipped_paths_unchanged(self, path):
324 assert path == extract_zipped_paths(path)325326 def test_zipped_paths_extracted(self, tmpdir):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 329–331why, one step back
329 f.write(__file__)
330331 _, name = os.path.splitdrive(__file__)

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 333–338why, one step back
333 extracted_path = extract_zipped_paths(zipped_path)
334335 assert extracted_path != zipped_path336 assert os.path.exists(extracted_path)337 assert filecmp.cmp(extracted_path, __file__)338

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 347–349why, one step back
347 assert not len(encodings)
348349 @pytest.mark.parametrize(

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 352–359why, one step back
352 # HTML5 meta charset attribute
353 '<meta charset="UTF-8">',354 # HTML4 pragma directive355 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">',356 # XHTML 1.x served with text/html MIME type357 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',358 # XHTML 1.x served as XML359 '<?xml version="1.0" encoding="UTF-8"?>',

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

lines 360–361why, one step back
360 ),
361 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 374–377why, one step back
374
375376class TestGuessJSONUTF:377 @pytest.mark.parametrize(

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

lines 378–389why, one step back
378 "encoding",
379 (380 "utf-32",381 "utf-8-sig",382 "utf-16",383 "utf-8",384 "utf-16-be",385 "utf-16-le",386 "utf-32-be",387 "utf-32-le",388 ),389 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 392–394why, one step back
392 assert guess_json_utf(data) == encoding
393394 def test_bad_utf_like_encoding(self):

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

lines 398–405why, one step back
398 ("encoding", "expected"),
399 (400 ("utf-16-be", "utf-16"),401 ("utf-16-le", "utf-16"),402 ("utf-32-be", "utf-32"),403 ("utf-32-le", "utf-32"),404 ),405 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 419why, one step back
419 (

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 422why, one step back
422 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 424why, one step back
424 (

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 427why, one step back
427 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 429why, one step back
429 (

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 436why, one step back
436 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 440–444why, one step back
440def test_get_auth_from_url(url, auth):
441 assert get_auth_from_url(url) == auth442443444@pytest.mark.parametrize(

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

lines 445–446why, one step back
445 "uri, expected",
446 (

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 456why, one step back
456 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 459–464why, one step back
459def test_requote_uri_with_unquoted_percents(uri, expected):
460 """See: https://github.com/psf/requests/issues/2356"""461 assert requote_uri(uri) == expected462463464@pytest.mark.parametrize(

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 479–483why, one step back
479def test_unquote_unreserved(uri, expected):
480 assert unquote_unreserved(uri) == expected481482483@pytest.mark.parametrize(

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

lines 484–490why, one step back
484 "mask, expected",
485 (486 (8, "255.0.0.0"),487 (24, "255.255.255.0"),488 (25, "255.255.255.128"),489 ),490)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 491–494why, one step back
491def test_dotted_netmask(mask, expected):
492 assert dotted_netmask(mask) == expected493494

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

lines 495–507why, one step back
495http_proxies = {
496 "http": "http://http.proxy",497 "http://some.host": "http://some.host.proxy",498}499all_proxies = {500 "all": "socks5://http.proxy",501 "all://some.host": "socks5://some.host.proxy",502}503mixed_proxies = {504 "http": "http://http.proxy",505 "http://some.host": "http://some.host.proxy",506 "all": "socks5://http.proxy",507}

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 508–509why, one step back
508
509

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

lines 510–526why, one step back
510@pytest.mark.parametrize(
511 "url, expected, proxies",512 (513 ("hTTp://u:p@Some.Host/path", "http://some.host.proxy", http_proxies),514 ("hTTp://u:p@Other.Host/path", "http://http.proxy", http_proxies),515 ("hTTp:///path", "http://http.proxy", http_proxies),516 ("hTTps://Other.Host", None, http_proxies),517 ("file:///etc/motd", None, http_proxies),518 ("hTTp://u:p@Some.Host/path", "socks5://some.host.proxy", all_proxies),519 ("hTTp://u:p@Other.Host/path", "socks5://http.proxy", all_proxies),520 ("hTTp:///path", "socks5://http.proxy", all_proxies),521 ("hTTps://Other.Host", "socks5://http.proxy", all_proxies),522 ("http://u:p@other.host/path", "http://http.proxy", mixed_proxies),523 ("http://u:p@some.host/path", "http://some.host.proxy", mixed_proxies),524 ("https://u:p@other.host/path", "socks5://http.proxy", mixed_proxies),525 ("https://u:p@some.host/path", "socks5://http.proxy", mixed_proxies),526 ("https://", "socks5://http.proxy", mixed_proxies),

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 531–536why, one step back
531def test_select_proxies(url, expected, proxies):
532 """Make sure we can select per-host proxies correctly."""533 assert select_proxy(url, proxies) == expected534535536@pytest.mark.parametrize(

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

lines 537–542why, one step back
537 "value, expected",
538 (539 ('foo="is a fish", bar="as well"', {"foo": "is a fish", "bar": "as well"}),540 ("key_without_value", {"key_without_value": None}),541 ),542)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 543–547why, one step back
543def test_parse_dict_header(value, expected):
544 assert parse_dict_header(value) == expected545546547@pytest.mark.parametrize(

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

lines 548–550why, one step back
548 "value, expected",
549 (550 ("application/xml", ("application/xml", {})),

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 551why, one step back
551 (

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 558why, one step back
558 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 560why, one step back
560 (

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

lines 561–569why, one step back
561 "multipart/form-data; boundary = something ; boundary2='something_else' ; no_equals ",
562 (563 "multipart/form-data",564 {565 "boundary": "something",566 "boundary2": "something_else",567 "no_equals": True,568 },569 ),

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

lines 572–580why, one step back
572 'multipart/form-data; boundary = something ; boundary2="something_else" ; no_equals ',
573 (574 "multipart/form-data",575 {576 "boundary": "something",577 "boundary2": "something_else",578 "no_equals": True,579 },580 ),

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 592–594why, one step back
592 ),
593 (594 'multipart/form-data; boundary = something ; "boundary2=something_else" ; no_equals ',

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

lines 595–602why, one step back
595 (
596 "multipart/form-data",597 {598 "boundary": "something",599 "boundary2": "something_else",600 "no_equals": True,601 },602 ),

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 603why, one step back
603 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 607–611why, one step back
607def test__parse_content_type_header(value, expected):
608 assert _parse_content_type_header(value) == expected609610611@pytest.mark.parametrize(

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

lines 612–614why, one step back
612 "value, expected",
613 (614 (CaseInsensitiveDict(), None),

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 615why, one step back
615 (

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 618why, one step back
618 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 622–626why, one step back
622def test_get_encoding_from_headers(value, expected):
623 assert get_encoding_from_headers(value) == expected624625626@pytest.mark.parametrize(

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

lines 627–636why, one step back
627 "value, length",
628 (629 ("", 0),630 ("T", 1),631 ("Test", 4),632 ("Cont", 0),633 ("Other", -5),634 ("Content", None),635 ),636)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 637–645why, one step back
637def test_iter_slices(value, length):
638 if length is None or (length <= 0 and len(value) > 0):639 # Reads all content at once640 assert len(list(iter_slices(value, length))) == 1641 else:642 assert len(list(iter_slices(value, 1))) == length643644645@pytest.mark.parametrize(

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

lines 646–647why, one step back
646 "value, expected",
647 (

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 651why, one step back
651 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 654–656why, one step back
654 (
655 '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;',656 [

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

lines 657–659why, one step back
657 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
658 {"url": "http://.../back.jpeg"},659 ],

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 660why, one step back
660 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 664–668why, one step back
664def test_parse_header_links(value, expected):
665 assert parse_header_links(value) == expected666667668@pytest.mark.parametrize(

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

lines 669–673why, one step back
669 "value, expected",
670 (671 ("example.com/path", "http://example.com/path"),672 ("//example.com/path", "http://example.com/path"),673 ("example.com:80", "http://example.com:80"),

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

line 674why, one step back
674 (

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

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

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

line 677why, one step back
677 ),

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 683–685why, one step back
683
684685@pytest.mark.parametrize(

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 693–697why, one step back
693def test_to_native_string(value, expected):
694 assert to_native_string(value) == expected695696697@pytest.mark.parametrize(

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

lines 698–707why, one step back
698 "url, expected",
699 (700 ("http://u:p@example.com/path?a=1#test", "http://example.com/path?a=1"),701 ("http://example.com/path", "http://example.com/path"),702 ("//u:p@example.com/path", "//example.com/path"),703 ("//example.com/path", "//example.com/path"),704 ("example.com/path", "//example.com/path"),705 ("scheme:u:p@example.com/path", "scheme://example.com/path"),706 ),707)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 708–712why, one step back
708def test_urldefragauth(url, expected):
709 assert urldefragauth(url) == expected710711712@pytest.mark.parametrize(

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

lines 713–726why, one step back
713 "url, expected",
714 (715 ("http://192.168.0.1:5000/", True),716 ("http://192.168.0.1/", True),717 ("http://172.16.1.1/", True),718 ("http://172.16.1.1:5000/", True),719 ("http://localhost.localdomain:5000/v1.0/", True),720 ("http://google.com:6000/", True),721 ("http://172.16.1.12/", False),722 ("http://172.16.1.12:5000/", False),723 ("http://google.com:5000/v1.0/", False),724 ("file:///some/path/on/disk", True),725 ),726)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 727–730why, one step back
727def test_should_bypass_proxies(url, expected, monkeypatch):
728 """Tests for function should_bypass_proxies to check if proxy729 can be bypassed or not730 """

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

lines 731–738why, one step back
731 monkeypatch.setenv(
732 "no_proxy",733 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",734 )735 monkeypatch.setenv(736 "NO_PROXY",737 "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1, google.com:6000",738 )

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 739–742why, one step back
739 assert should_bypass_proxies(url, no_proxy=None) == expected
740741742@pytest.mark.parametrize(

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

lines 743–754why, one step back
743 "url, expected",
744 (745 ("http://172.16.1.1/", "172.16.1.1"),746 ("http://172.16.1.1:5000/", "172.16.1.1"),747 ("http://user:pass@172.16.1.1", "172.16.1.1"),748 ("http://user:pass@172.16.1.1:5000", "172.16.1.1"),749 ("http://hostname/", "hostname"),750 ("http://hostname:5000/", "hostname"),751 ("http://user:pass@hostname", "hostname"),752 ("http://user:pass@hostname:5000", "hostname"),753 ),754)

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 762–764why, one step back
762
763764@pytest.mark.parametrize(

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

lines 765–766why, one step back
765 "cookiejar",
766 (

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 771–774why, one step back
771def test_add_dict_to_cookiejar(cookiejar):
772 """Ensure add_dict_to_cookiejar works for773 non-RequestsCookieJar CookieJars774 """

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 776–781why, one step back
776 cj = add_dict_to_cookiejar(cookiejar, cookiedict)
777 cookies = {cookie.name: cookie.value for cookie in cj}778 assert cookiedict == cookies779780781@pytest.mark.parametrize(

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

lines 782–787why, one step back
782 "value, expected",
783 (784 ("test", True),785 ("æíöû", False),786 ("ジェーピーニック", False),787 ),

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 788–793why, one step back
788)
789def test_unicode_is_ascii(value, expected):790 assert unicode_is_ascii(value) is expected791792793@pytest.mark.parametrize(

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

lines 794–806why, one step back
794 "url, expected",
795 (796 ("http://192.168.0.1:5000/", True),797 ("http://192.168.0.1/", True),798 ("http://172.16.1.1/", True),799 ("http://172.16.1.1:5000/", True),800 ("http://localhost.localdomain:5000/v1.0/", True),801 ("http://172.16.1.12/", False),802 ("http://172.16.1.12:5000/", False),803 ("http://google.com:5000/v1.0/", False),804 ),805)806def test_should_bypass_proxies_no_proxy(url, expected, monkeypatch):

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 811–814why, one step back
811 # Test 'no_proxy' argument
812 assert should_bypass_proxies(url, no_proxy=no_proxy) == expected813814

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

lines 817–831why, one step back
817 "url, expected, override",
818 (819 ("http://192.168.0.1:5000/", True, None),820 ("http://192.168.0.1/", True, None),821 ("http://172.16.1.1/", True, None),822 ("http://172.16.1.1:5000/", True, None),823 ("http://localhost.localdomain:5000/v1.0/", True, None),824 ("http://172.16.1.22/", False, None),825 ("http://172.16.1.22:5000/", False, None),826 ("http://google.com:5000/v1.0/", False, None),827 ("http://mylocalhostname:5000/v1.0/", True, "<local>"),828 ("http://192.168.0.1/", False, ""),829 ),830)831def test_should_bypass_proxies_win_registry(url, expected, override, monkeypatch):

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 832–835why, one step back
832 """Tests for function should_bypass_proxies to check if proxy
833 can be bypassed or not with Windows registry settings834 """835 if override is None:

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

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

Farewell, sweet Concorde!Nate Prewittbefore adoption8bce583

line 837why, one step back
837 import winreg

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 838–850why, one step back
838
839 class RegHandle:840 def Close(self):841 pass842843 ie_settings = RegHandle()844 proxyEnableValues = deque([1, "1"])845846 def OpenKey(key, subkey):847 return ie_settings848849 def QueryValueEx(key, value_name):850 if key is ie_settings:

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

lines 858–864why, one step back
858 monkeypatch.setenv("http_proxy", "")
859 monkeypatch.setenv("https_proxy", "")860 monkeypatch.setenv("ftp_proxy", "")861 monkeypatch.setenv("no_proxy", "")862 monkeypatch.setenv("NO_PROXY", "")863 monkeypatch.setattr(winreg, "OpenKey", OpenKey)864 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 865–867why, one step back
865 assert should_bypass_proxies(url, None) == expected
866867

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

lines 868–900why, one step back
868@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")
869def test_should_bypass_proxies_win_registry_bad_values(monkeypatch):870 """Tests for function should_bypass_proxies to check if proxy871 can be bypassed or not with Windows invalid registry settings.872 """873 import winreg874875 class RegHandle:876 def Close(self):877 pass878879 ie_settings = RegHandle()880881 def OpenKey(key, subkey):882 return ie_settings883884 def QueryValueEx(key, value_name):885 if key is ie_settings:886 if value_name == "ProxyEnable":887 # Invalid response; Should be an int or int-y value888 return [""]889 elif value_name == "ProxyOverride":890 return ["192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1"]891892 monkeypatch.setenv("http_proxy", "")893 monkeypatch.setenv("https_proxy", "")894 monkeypatch.setenv("no_proxy", "")895 monkeypatch.setenv("NO_PROXY", "")896 monkeypatch.setattr(winreg, "OpenKey", OpenKey)897 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)898 assert should_bypass_proxies("http://172.16.1.1/", None) is False899900

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

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

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

lines 902–909why, one step back
902 "env_name, value",
903 (904 ("no_proxy", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),905 ("no_proxy", None),906 ("a_new_key", "192.168.0.0/24,127.0.0.1,localhost.localdomain"),907 ("a_new_key", None),908 ),909)

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

lines 910–922why, one step back
910def test_set_environ(env_name, value):
911 """Tests set_environ will set environ values and will restore the environ."""912 environ_copy = copy.deepcopy(os.environ)913 with set_environ(env_name, value):914 assert os.environ.get(env_name) == value915916 assert os.environ == environ_copy917918919def test_set_environ_raises_exception():920 """Tests set_environ will raise exceptions in context when the921 value parameter is None."""922 with pytest.raises(Exception) as exception:

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

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

Remove Pipfile/Pipfile.lockNate Prewittbefore adoption320a10d

line 925why, one step back
925

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

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

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

lines 927–958why, one step back
927
928929@pytest.mark.skipif(os.name != "nt", reason="Test only on Windows")930def test_should_bypass_proxies_win_registry_ProxyOverride_value(monkeypatch):931 """Tests for function should_bypass_proxies to check if proxy932 can be bypassed or not with Windows ProxyOverride registry value ending with a semicolon.933 """934 import winreg935936 class RegHandle:937 def Close(self):938 pass939940 ie_settings = RegHandle()941942 def OpenKey(key, subkey):943 return ie_settings944945 def QueryValueEx(key, value_name):946 if key is ie_settings:947 if value_name == "ProxyEnable":948 return [1]949 elif value_name == "ProxyOverride":950 return [951 "192.168.*;127.0.0.1;localhost.localdomain;172.16.1.1;<-loopback>;"952 ]953954 monkeypatch.setenv("NO_PROXY", "")955 monkeypatch.setenv("no_proxy", "")956 monkeypatch.setattr(winreg, "OpenKey", OpenKey)957 monkeypatch.setattr(winreg, "QueryValueEx", QueryValueEx)958 assert should_bypass_proxies("http://example.com/", None) is False