Skip to content
Myr

test_requests.py

This file

Path

tests/test_requests.py

2,839 lines · 97.3 KiB · Python

Last changed by

Merge pull request #6589 from bruceadams/super_len_str_utf-8Ian Stapleton Cordascobefore adoptionb8be93a

History of this file

Take it

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

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1why, one step back
1"""Tests for Requests."""

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

line 2why, one step back
2

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 3–5why, one step back
3import collections
4import contextlib5import io

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

lines 6–10why, one step back
6import json
7import os8import pickle9import re10import warnings

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

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

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

line 12why, one step back
12

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 13why, one step back
13import pytest

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 14why, one step back
14import urllib3

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 15why, one step back
15from urllib3.util import Timeout as Urllib3Timeout

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

lines 16–51why, one step back
16
17import requests18from requests.adapters import HTTPAdapter19from requests.auth import HTTPDigestAuth, _basic_auth_str20from requests.compat import (21 JSONDecodeError,22 Morsel,23 MutableMapping,24 builtin_str,25 cookielib,26 getproxies,27 urlparse,28)29from requests.cookies import cookiejar_from_dict, morsel_to_cookie30from requests.exceptions import (31 ChunkedEncodingError,32 ConnectionError,33 ConnectTimeout,34 ContentDecodingError,35 InvalidHeader,36 InvalidProxyURL,37 InvalidSchema,38 InvalidURL,39 MissingSchema,40 ProxyError,41 ReadTimeout,42 RequestException,43 RetryError,44)45from requests.exceptions import SSLError as RequestsSSLError46from requests.exceptions import Timeout, TooManyRedirects, UnrewindableBodyError47from requests.hooks import default_hooks48from requests.models import PreparedRequest, urlencode49from requests.sessions import SessionRedirectMixin50from requests.structures import CaseInsensitiveDict51

Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590

line 52why, one step back
52from . import SNIMissingWarning

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

lines 53–55why, one step back
53from .compat import StringIO
54from .utils import override_environ55

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 56–57why, one step back
56# Requests to this URL should always fail with a connection timeout (nothing
57# listening on that port)

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

lines 58–59why, one step back
58TARPIT = "http://10.255.255.1"
59

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 60why, one step back
60# This is to avoid waiting the timeout of using TARPIT

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

lines 61–63why, one step back
61INVALID_PROXY = "http://localhost:1"
6263try:

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 64why, one step back
64 from ssl import SSLContext

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

line 65why, one step back
65

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 66–69why, one step back
66 del SSLContext
67 HAS_MODERN_SSL = True68except ImportError:69 HAS_MODERN_SSL = False

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

lines 70–71why, one step back
70
71try:

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 72–75why, one step back
72 requests.pyopenssl
73 HAS_PYOPENSSL = True74except AttributeError:75 HAS_PYOPENSSL = False

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

lines 76–77why, one step back
76
77

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 78why, one step back
78class TestRequests:

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

lines 79–80why, one step back
79 digest_auth_algo = ("MD5", "SHA-256", "SHA-512")
80

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 81–90why, one step back
81 def test_entry_points(self):
82 requests.session83 requests.session().get84 requests.session().head85 requests.get86 requests.head87 requests.put88 requests.patch89 requests.post90 # Not really an entry point, but people rely on it.

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

lines 91–104why, one step back
91 from requests.packages.urllib3.poolmanager import PoolManager # noqa:F401
9293 @pytest.mark.parametrize(94 "exception, url",95 (96 (MissingSchema, "hiwpefhipowhefopw"),97 (InvalidSchema, "localhost:3128"),98 (InvalidSchema, "localhost.localdomain:3128/"),99 (InvalidSchema, "10.122.1.1:3128/"),100 (InvalidURL, "http://"),101 (InvalidURL, "http://*example.com"),102 (InvalidURL, "http://.example.com"),103 ),104 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 105why, one step back
105 def test_invalid_url(self, exception, url):

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

line 106why, one step back
106 with pytest.raises(exception):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 107why, one step back
107 requests.get(url)

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

line 108why, one step back
108

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 109–110why, one step back
109 def test_basic_building(self):
110 req = requests.Request()

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

lines 111–113why, one step back
111 req.url = "http://kennethreitz.org/"
112 req.data = {"life": "42"}113

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 114–115why, one step back
114 pr = req.prepare()
115 assert pr.url == req.url

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

lines 116–118why, one step back
116 assert pr.body == "life=42"
117118 @pytest.mark.parametrize("method", ("GET", "HEAD"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 119why, one step back
119 def test_no_content_length(self, httpbin, method):

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

lines 120–123why, one step back
120 req = requests.Request(method, httpbin(method.lower())).prepare()
121 assert "Content-Length" not in req.headers122123 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 124why, one step back
124 def test_no_body_content_length(self, httpbin, method):

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

lines 125–128why, one step back
125 req = requests.Request(method, httpbin(method.lower())).prepare()
126 assert req.headers["Content-Length"] == "0"127128 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 129why, one step back
129 def test_empty_content_length(self, httpbin, method):

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

lines 130–132why, one step back
130 req = requests.Request(method, httpbin(method.lower()), data="").prepare()
131 assert req.headers["Content-Length"] == "0"132

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 133why, one step back
133 def test_override_content_length(self, httpbin):

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

lines 134–138why, one step back
134 headers = {"Content-Length": "not zero"}
135 r = requests.Request("POST", httpbin("post"), headers=headers).prepare()136 assert "Content-Length" in r.headers137 assert r.headers["Content-Length"] == "not zero"138

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 139why, one step back
139 def test_path_is_not_double_encoded(self):

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

lines 140–156why, one step back
140 request = requests.Request("GET", "http://0.0.0.0/get/test case").prepare()
141142 assert request.path_url == "/get/test%20case"143144 @pytest.mark.parametrize(145 "url, expected",146 (147 (148 "http://example.com/path#fragment",149 "http://example.com/path?a=b#fragment",150 ),151 (152 "http://example.com/path?key=value#fragment",153 "http://example.com/path?key=value&a=b#fragment",154 ),155 ),156 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 157why, one step back
157 def test_params_are_added_before_fragment(self, url, expected):

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

line 158why, one step back
158 request = requests.Request("GET", url, params={"a": "b"}).prepare()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 159why, one step back
159 assert request.url == expected

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

line 160why, one step back
160

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 161why, one step back
161 def test_params_original_order_is_preserved_by_default(self):

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

lines 162–168why, one step back
162 param_ordered_dict = collections.OrderedDict(
163 (("z", 1), ("a", 1), ("k", 1), ("d", 1))164 )165 session = requests.Session()166 request = requests.Request(167 "GET", "http://example.com/", params=param_ordered_dict168 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 169why, one step back
169 prep = session.prepare_request(request)

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

lines 170–171why, one step back
170 assert prep.url == "http://example.com/?z=1&a=1&k=1&d=1"
171

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 172why, one step back
172 def test_params_bytes_are_encoded(self):

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

lines 173–177why, one step back
173 request = requests.Request(
174 "GET", "http://example.com", params=b"test=foo"175 ).prepare()176 assert request.url == "http://example.com/?test=foo"177

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 178why, one step back
178 def test_binary_put(self):

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

lines 179–181why, one step back
179 request = requests.Request(
180 "PUT", "http://example.com", data="ööö".encode()181 ).prepare()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 182why, one step back
182 assert isinstance(request.body, bytes)

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

line 183why, one step back
183

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 184–185why, one step back
184 def test_whitespaces_are_removed_from_url(self):
185 # Test for issue #3696

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

lines 186–189why, one step back
186 request = requests.Request("GET", " http://example.com").prepare()
187 assert request.url == "http://example.com/"188189 @pytest.mark.parametrize("scheme", ("http://", "HTTP://", "hTTp://", "HttP://"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 190why, one step back
190 def test_mixed_case_scheme_acceptable(self, httpbin, scheme):

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

lines 191–193why, one step back
191 s = requests.Session()
192 s.proxies = getproxies()193 parts = urlparse(httpbin("get"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 194why, one step back
194 url = scheme + parts.netloc + parts.path

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

lines 195–198why, one step back
195 r = requests.Request("GET", url)
196 r = s.send(r.prepare())197 assert r.status_code == 200, f"failed for scheme {scheme}"198

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 199why, one step back
199 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):

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

lines 200–207why, one step back
200 r = requests.Request("GET", httpbin("get"))
201 s = requests.Session()202 s.proxies = getproxies()203204 r = s.send(r.prepare())205206 assert r.status_code == 200207

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 208why, one step back
208 def test_HTTP_302_ALLOW_REDIRECT_GET(self, httpbin):

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

lines 209–213why, one step back
209 r = requests.get(httpbin("redirect", "1"))
210 assert r.status_code == 200211 assert r.history[0].status_code == 302212 assert r.history[0].is_redirect213

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 214why, one step back
214 def test_HTTP_307_ALLOW_REDIRECT_POST(self, httpbin):

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

lines 215–224why, one step back
215 r = requests.post(
216 httpbin("redirect-to"),217 data="test",218 params={"url": "post", "status_code": 307},219 )220 assert r.status_code == 200221 assert r.history[0].status_code == 307222 assert r.history[0].is_redirect223 assert r.json()["data"] == "test"224

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 225why, one step back
225 def test_HTTP_307_ALLOW_REDIRECT_POST_WITH_SEEKABLE(self, httpbin):

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

lines 226–236why, one step back
226 byte_str = b"test"
227 r = requests.post(228 httpbin("redirect-to"),229 data=io.BytesIO(byte_str),230 params={"url": "post", "status_code": 307},231 )232 assert r.status_code == 200233 assert r.history[0].status_code == 307234 assert r.history[0].is_redirect235 assert r.json()["data"] == byte_str.decode("utf-8")236

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 237why, one step back
237 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):

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

lines 238–243why, one step back
238 try:
239 requests.get(httpbin("relative-redirect", "50"))240 except TooManyRedirects as e:241 url = httpbin("relative-redirect", "20")242 assert e.request.url == url243 assert e.response.url == url

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 244why, one step back
244 assert len(e.response.history) == 30

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

lines 245–247why, one step back
245 else:
246 pytest.fail("Expected redirect to raise TooManyRedirects but it did not")247

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 248why, one step back
248 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):

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

line 249why, one step back
249 s = requests.session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 250why, one step back
250 s.max_redirects = 5

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

lines 251–256why, one step back
251 try:
252 s.get(httpbin("relative-redirect", "50"))253 except TooManyRedirects as e:254 url = httpbin("relative-redirect", "45")255 assert e.request.url == url256 assert e.response.url == url

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 257why, one step back
257 assert len(e.response.history) == 5

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

lines 258–262why, one step back
258 else:
259 pytest.fail(260 "Expected custom max number of redirects to be respected but was not"261 )262

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 263why, one step back
263 def test_http_301_changes_post_to_get(self, httpbin):

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

lines 264–269why, one step back
264 r = requests.post(httpbin("status", "301"))
265 assert r.status_code == 200266 assert r.request.method == "GET"267 assert r.history[0].status_code == 301268 assert r.history[0].is_redirect269

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 270why, one step back
270 def test_http_301_doesnt_change_head_to_get(self, httpbin):

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

line 271why, one step back
271 r = requests.head(httpbin("status", "301"), allow_redirects=True)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 272why, one step back
272 print(r.content)

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

lines 273–277why, one step back
273 assert r.status_code == 200
274 assert r.request.method == "HEAD"275 assert r.history[0].status_code == 301276 assert r.history[0].is_redirect277

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 278why, one step back
278 def test_http_302_changes_post_to_get(self, httpbin):

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

lines 279–284why, one step back
279 r = requests.post(httpbin("status", "302"))
280 assert r.status_code == 200281 assert r.request.method == "GET"282 assert r.history[0].status_code == 302283 assert r.history[0].is_redirect284

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 285why, one step back
285 def test_http_302_doesnt_change_head_to_get(self, httpbin):

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

lines 286–291why, one step back
286 r = requests.head(httpbin("status", "302"), allow_redirects=True)
287 assert r.status_code == 200288 assert r.request.method == "HEAD"289 assert r.history[0].status_code == 302290 assert r.history[0].is_redirect291

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 292why, one step back
292 def test_http_303_changes_post_to_get(self, httpbin):

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

lines 293–298why, one step back
293 r = requests.post(httpbin("status", "303"))
294 assert r.status_code == 200295 assert r.request.method == "GET"296 assert r.history[0].status_code == 303297 assert r.history[0].is_redirect298

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 299why, one step back
299 def test_http_303_doesnt_change_head_to_get(self, httpbin):

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

lines 300–305why, one step back
300 r = requests.head(httpbin("status", "303"), allow_redirects=True)
301 assert r.status_code == 200302 assert r.request.method == "HEAD"303 assert r.history[0].status_code == 303304 assert r.history[0].is_redirect305

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 306why, one step back
306 def test_header_and_body_removal_on_redirect(self, httpbin):

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

lines 307–310why, one step back
307 purged_headers = ("Content-Length", "Content-Type")
308 ses = requests.Session()309 req = requests.Request("POST", httpbin("post"), data={"test": "data"})310 prep = ses.prepare_request(req)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 311why, one step back
311 resp = ses.send(prep)

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

lines 312–316why, one step back
312
313 # Mimic a redirect response314 resp.status_code = 302315 resp.headers["location"] = "get"316

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 317why, one step back
317 # Run request through resolve_redirects

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

lines 318–322why, one step back
318 next_resp = next(ses.resolve_redirects(resp, prep))
319 assert next_resp.request.body is None320 for header in purged_headers:321 assert header not in next_resp.request.headers322

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 323why, one step back
323 def test_transfer_enc_removal_on_redirect(self, httpbin):

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

lines 324–329why, one step back
324 purged_headers = ("Transfer-Encoding", "Content-Type")
325 ses = requests.Session()326 req = requests.Request("POST", httpbin("post"), data=(b"x" for x in range(1)))327 prep = ses.prepare_request(req)328 assert "Transfer-Encoding" in prep.headers329

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 330why, one step back
330 # Create Response to avoid https://github.com/kevin1024/pytest-httpbin/issues/33

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

lines 331–332why, one step back
331 resp = requests.Response()
332 resp.raw = io.BytesIO(b"the content")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 333why, one step back
333 resp.request = prep

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

lines 334–339why, one step back
334 setattr(resp.raw, "release_conn", lambda *args: args)
335336 # Mimic a redirect response337 resp.status_code = 302338 resp.headers["location"] = httpbin("get")339

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 340why, one step back
340 # Run request through resolve_redirect

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

lines 341–345why, one step back
341 next_resp = next(ses.resolve_redirects(resp, prep))
342 assert next_resp.request.body is None343 for header in purged_headers:344 assert header not in next_resp.request.headers345

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 346–347why, one step back
346 def test_fragment_maintained_on_redirect(self, httpbin):
347 fragment = "#view=edit&token=hunter2"

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

lines 348–349why, one step back
348 r = requests.get(httpbin("redirect-to?url=get") + fragment)
349

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 350why, one step back
350 assert len(r.history) > 0

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

lines 351–353why, one step back
351 assert r.history[0].request.url == httpbin("redirect-to?url=get") + fragment
352 assert r.url == httpbin("get") + fragment353

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 354why, one step back
354 def test_HTTP_200_OK_GET_WITH_PARAMS(self, httpbin):

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

lines 355–361why, one step back
355 heads = {"User-agent": "Mozilla/5.0"}
356357 r = requests.get(httpbin("user-agent"), headers=heads)358359 assert heads["User-agent"] in r.text360 assert r.status_code == 200361

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 362why, one step back
362 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self, httpbin):

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

lines 363–369why, one step back
363 heads = {"User-agent": "Mozilla/5.0"}
364365 r = requests.get(366 httpbin("get") + "?test=true", params={"q": "test"}, headers=heads367 )368 assert r.status_code == 200369

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 370why, one step back
370 def test_set_cookie_on_301(self, httpbin):

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

lines 371–375why, one step back
371 s = requests.session()
372 url = httpbin("cookies/set?foo=bar")373 s.get(url)374 assert s.cookies["foo"] == "bar"375

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 376why, one step back
376 def test_cookie_sent_on_redirect(self, httpbin):

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

lines 377–381why, one step back
377 s = requests.session()
378 s.get(httpbin("cookies/set?foo=bar"))379 r = s.get(httpbin("redirect/1")) # redirects to httpbin('get')380 assert "Cookie" in r.json()["headers"]381

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 382why, one step back
382 def test_cookie_removed_on_expire(self, httpbin):

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

lines 383–385why, one step back
383 s = requests.session()
384 s.get(httpbin("cookies/set?foo=bar"))385 assert s.cookies["foo"] == "bar"

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 386why, one step back
386 s.get(

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

lines 387–391why, one step back
387 httpbin("response-headers"),
388 params={"Set-Cookie": "foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT"},389 )390 assert "foo" not in s.cookies391

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 392why, one step back
392 def test_cookie_quote_wrapped(self, httpbin):

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

line 393why, one step back
393 s = requests.session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 394why, one step back
394 s.get(httpbin('cookies/set?foo="bar:baz"'))

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

lines 395–396why, one step back
395 assert s.cookies["foo"] == '"bar:baz"'
396

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 397why, one step back
397 def test_cookie_persists_via_api(self, httpbin):

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

lines 398–402why, one step back
398 s = requests.session()
399 r = s.get(httpbin("redirect/1"), cookies={"foo": "bar"})400 assert "foo" in r.request.headers["Cookie"]401 assert "foo" in r.history[0].request.headers["Cookie"]402

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 403why, one step back
403 def test_request_cookie_overrides_session_cookie(self, httpbin):

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

lines 404–407why, one step back
404 s = requests.session()
405 s.cookies["foo"] = "bar"406 r = s.get(httpbin("cookies"), cookies={"foo": "baz"})407 assert r.json()["cookies"]["foo"] == "baz"

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 408why, one step back
408 # Session cookie should not be modified

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

lines 409–410why, one step back
409 assert s.cookies["foo"] == "bar"
410

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 411why, one step back
411 def test_request_cookies_not_persisted(self, httpbin):

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

lines 412–413why, one step back
412 s = requests.session()
413 s.get(httpbin("cookies"), cookies={"foo": "baz"})

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 414–415why, one step back
414 # Sending a request with cookies should not add cookies to the session
415 assert not s.cookies

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

line 416why, one step back
416

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 417why, one step back
417 def test_generic_cookiejar_works(self, httpbin):

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

lines 418–420why, one step back
418 cj = cookielib.CookieJar()
419 cookiejar_from_dict({"foo": "bar"}, cj)420 s = requests.session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 421why, one step back
421 s.cookies = cj

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

lines 422–424why, one step back
422 r = s.get(httpbin("cookies"))
423 # Make sure the cookie was sent424 assert r.json()["cookies"]["foo"] == "bar"

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 425–426why, one step back
425 # Make sure the session cj is still the custom one
426 assert s.cookies is cj

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

line 427why, one step back
427

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 428why, one step back
428 def test_param_cookiejar_works(self, httpbin):

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

lines 429–435why, one step back
429 cj = cookielib.CookieJar()
430 cookiejar_from_dict({"foo": "bar"}, cj)431 s = requests.session()432 r = s.get(httpbin("cookies"), cookies=cj)433 # Make sure the cookie was sent434 assert r.json()["cookies"]["foo"] == "bar"435

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 436–438why, one step back
436 def test_cookielib_cookiejar_on_redirect(self, httpbin):
437 """Tests resolve_redirect doesn't fail when merging cookies438 with non-RequestsCookieJar cookiejar.

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

line 439why, one step back
439

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 440why, one step back
440 See GH #3579

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

lines 441–445why, one step back
441 """
442 cj = cookiejar_from_dict({"foo": "bar"}, cookielib.CookieJar())443 s = requests.Session()444 s.cookies = cookiejar_from_dict({"cookie": "tasty"})445

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 446why, one step back
446 # Prepare request without using Session

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

line 447why, one step back
447 req = requests.Request("GET", httpbin("headers"), cookies=cj)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 448why, one step back
448 prep_req = req.prepare()

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

line 449why, one step back
449

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 450–451why, one step back
450 # Send request and simulate redirect
451 resp = s.send(prep_req)

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

lines 452–453why, one step back
452 resp.status_code = 302
453 resp.headers["location"] = httpbin("get")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 454–455why, one step back
454 redirects = s.resolve_redirects(resp, prep_req)
455 resp = next(redirects)

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

line 456why, one step back
456

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 457–460why, one step back
457 # Verify CookieJar isn't being converted to RequestsCookieJar
458 assert isinstance(prep_req._cookies, cookielib.CookieJar)459 assert isinstance(resp.request._cookies, cookielib.CookieJar)460 assert not isinstance(resp.request._cookies, requests.cookies.RequestsCookieJar)

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

line 461why, one step back
461

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 462–464why, one step back
462 cookies = {}
463 for c in resp.request._cookies:464 cookies[c.name] = c.value

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

lines 465–467why, one step back
465 assert cookies["foo"] == "bar"
466 assert cookies["cookie"] == "tasty"467

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 468why, one step back
468 def test_requests_in_history_are_not_overridden(self, httpbin):

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

line 469why, one step back
469 resp = requests.get(httpbin("redirect/3"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 470–472why, one step back
470 urls = [r.url for r in resp.history]
471 req_urls = [r.request.url for r in resp.history]472 assert urls == req_urls

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

line 473why, one step back
473

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 474–475why, one step back
474 def test_history_is_always_a_list(self, httpbin):
475 """Show that even with redirects, Response.history is always a list."""

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

lines 476–479why, one step back
476 resp = requests.get(httpbin("get"))
477 assert isinstance(resp.history, list)478 resp = requests.get(httpbin("redirect/1"))479 assert isinstance(resp.history, list)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 480why, one step back
480 assert not isinstance(resp.history, tuple)

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

line 481why, one step back
481

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 482–483why, one step back
482 def test_headers_on_session_with_None_are_not_sent(self, httpbin):
483 """Do not send headers in Session.headers with None values."""

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

lines 484–489why, one step back
484 ses = requests.Session()
485 ses.headers["Accept-Encoding"] = None486 req = requests.Request("GET", httpbin("get"))487 prep = ses.prepare_request(req)488 assert "Accept-Encoding" not in prep.headers489

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 490–491why, one step back
490 def test_headers_preserve_order(self, httpbin):
491 """Preserve order when headers provided as OrderedDict."""

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

line 492why, one step back
492 ses = requests.Session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 493why, one step back
493 ses.headers = collections.OrderedDict()

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

lines 494–501why, one step back
494 ses.headers["Accept-Encoding"] = "identity"
495 ses.headers["First"] = "1"496 ses.headers["Second"] = "2"497 headers = collections.OrderedDict([("Third", "3"), ("Fourth", "4")])498 headers["Fifth"] = "5"499 headers["Second"] = "222"500 req = requests.Request("GET", httpbin("get"), headers=headers)501 prep = ses.prepare_request(req)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 502why, one step back
502 items = list(prep.headers.items())

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

lines 503–510why, one step back
503 assert items[0] == ("Accept-Encoding", "identity")
504 assert items[1] == ("First", "1")505 assert items[2] == ("Second", "222")506 assert items[3] == ("Third", "3")507 assert items[4] == ("Fourth", "4")508 assert items[5] == ("Fifth", "5")509510 @pytest.mark.parametrize("key", ("User-agent", "user-agent"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 511why, one step back
511 def test_user_agent_transfers(self, httpbin, key):

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

lines 512–514why, one step back
512 heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}
513514 r = requests.get(httpbin("user-agent"), headers=heads)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 515why, one step back
515 assert heads[key] in r.text

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

line 516why, one step back
516

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 517why, one step back
517 def test_HTTP_200_OK_HEAD(self, httpbin):

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

lines 518–520why, one step back
518 r = requests.head(httpbin("get"))
519 assert r.status_code == 200520

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 521why, one step back
521 def test_HTTP_200_OK_PUT(self, httpbin):

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

lines 522–524why, one step back
522 r = requests.put(httpbin("put"))
523 assert r.status_code == 200524

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 525why, one step back
525 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self, httpbin):

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

lines 526–528why, one step back
526 auth = ("user", "pass")
527 url = httpbin("basic-auth", "user", "pass")528

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 529why, one step back
529 r = requests.get(url, auth=auth)

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

lines 530–531why, one step back
530 assert r.status_code == 200
531

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 532–533why, one step back
532 r = requests.get(url)
533 assert r.status_code == 401

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

lines 534–535why, one step back
534
535 s = requests.session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 536–537why, one step back
536 s.auth = auth
537 r = s.get(url)

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

lines 538–544why, one step back
538 assert r.status_code == 200
539540 @pytest.mark.parametrize(541 "username, password",542 (543 ("user", "pass"),544 ("имя".encode(), "пароль".encode()),

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 545–546why, one step back
545 (42, 42),
546 (None, None),

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

lines 547–548why, one step back
547 ),
548 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 549–550why, one step back
549 def test_set_basicauth(self, httpbin, username, password):
550 auth = (username, password)

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

lines 551–557why, one step back
551 url = httpbin("get")
552553 r = requests.Request("GET", url, auth=auth)554 p = r.prepare()555556 assert p.headers["Authorization"] == _basic_auth_str(username, password)557

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 558–560why, one step back
558 def test_basicauth_encodes_byte_strings(self):
559 """Ensure b'test' formats as the byte string "test" rather560 than the unicode string "b'test'" in Python 3.

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

lines 561–570why, one step back
561 """
562 auth = (b"\xc5\xafsername", b"test\xc6\xb6")563 r = requests.Request("GET", "http://localhost", auth=auth)564 p = r.prepare()565566 assert p.headers["Authorization"] == "Basic xa9zZXJuYW1lOnRlc3TGtg=="567568 @pytest.mark.parametrize(569 "url, exception",570 (

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 571why, one step back
571 # Connecting to an unknown domain should raise a ConnectionError

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

line 572why, one step back
572 ("http://doesnotexist.google.com", ConnectionError),

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 573why, one step back
573 # Connecting to an invalid port should raise a ConnectionError

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

line 574why, one step back
574 ("http://localhost:1", ConnectionError),

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 575why, one step back
575 # Inputing a URL that cannot be parsed should raise an InvalidURL error

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

lines 576–578why, one step back
576 ("http://fe80::5054:ff:fe5a:fc0", InvalidURL),
577 ),578 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 579why, one step back
579 def test_errors(self, url, exception):

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

line 580why, one step back
580 with pytest.raises(exception):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 581why, one step back
581 requests.get(url, timeout=1)

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

line 582why, one step back
582

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 583–585why, one step back
583 def test_proxy_error(self):
584 # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError585 with pytest.raises(ProxyError):

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

lines 586–589why, one step back
586 requests.get(
587 "http://localhost:1", proxies={"http": "non-resolvable-address"}588 )589

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 590why, one step back
590 def test_proxy_error_on_bad_url(self, httpbin, httpbin_secure):

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

lines 591–602why, one step back
591 with pytest.raises(InvalidProxyURL):
592 requests.get(httpbin_secure(), proxies={"https": "http:/badproxyurl:3128"})593594 with pytest.raises(InvalidProxyURL):595 requests.get(httpbin(), proxies={"http": "http://:8080"})596597 with pytest.raises(InvalidProxyURL):598 requests.get(httpbin_secure(), proxies={"https": "https://"})599600 with pytest.raises(InvalidProxyURL):601 requests.get(httpbin(), proxies={"http": "http:///example.com:8080"})602

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 603why, one step back
603 def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):

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

lines 604–609why, one step back
604 with override_environ(http_proxy=INVALID_PROXY):
605 with pytest.raises(ProxyError):606 session = requests.Session()607 request = requests.Request("GET", httpbin())608 session.send(request.prepare())609

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 610why, one step back
610 def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):

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

lines 611–614why, one step back
611 with override_environ(http_proxy=INVALID_PROXY):
612 with pytest.raises(ProxyError):613 session = requests.Session()614 request = requests.Request("GET", httpbin())

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

lines 615–616why, one step back
615 prepared = session.prepare_request(request)
616 session.send(prepared)

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

line 617why, one step back
617

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 618why, one step back
618 def test_respect_proxy_env_on_send_with_redirects(self, httpbin):

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

lines 619–622why, one step back
619 with override_environ(http_proxy=INVALID_PROXY):
620 with pytest.raises(ProxyError):621 session = requests.Session()622 url = httpbin("redirect/1")

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 623why, one step back
623 print(url)

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

lines 624–626why, one step back
624 request = requests.Request("GET", url)
625 session.send(request.prepare())626

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 627why, one step back
627 def test_respect_proxy_env_on_get(self, httpbin):

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

lines 628–630why, one step back
628 with override_environ(http_proxy=INVALID_PROXY):
629 with pytest.raises(ProxyError):630 session = requests.Session()

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 631why, one step back
631 session.get(httpbin())

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

line 632why, one step back
632

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 633why, one step back
633 def test_respect_proxy_env_on_request(self, httpbin):

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

lines 634–638why, one step back
634 with override_environ(http_proxy=INVALID_PROXY):
635 with pytest.raises(ProxyError):636 session = requests.Session()637 session.request(method="GET", url=httpbin())638

Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49

lines 639–640why, one step back
639 def test_proxy_authorization_preserved_on_request(self, httpbin):
640 proxy_auth_value = "Bearer XXX"

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

line 641why, one step back
641 session = requests.Session()

Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49

line 642why, one step back
642 session.headers.update({"Proxy-Authorization": proxy_auth_value})

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

lines 643–645why, one step back
643 resp = session.request(method="GET", url=httpbin("get"))
644 sent_headers = resp.json().get("headers", {})645

Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49

line 646why, one step back
646 assert sent_headers.get("Proxy-Authorization") == proxy_auth_value

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

line 647why, one step back
647

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 648–650why, one step back
648 @pytest.mark.parametrize(
649 "url,has_proxy_auth",650 (

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 651–652why, one step back
651 ("http://example.com", True),
652 ("https://example.com", False),

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

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

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 655–657why, one step back
655 def test_proxy_authorization_not_appended_to_https_request(
656 self, url, has_proxy_auth657 ):

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 658–659why, one step back
658 session = requests.Session()
659 proxies = {

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 660–661why, one step back
660 "http": "http://test:pass@localhost:8080",
661 "https": "http://test:pass@localhost:8090",

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

line 662why, one step back
662 }

Fix linting issuesNate Prewittbefore adoption6e5b15d

line 663why, one step back
663 req = requests.Request("GET", url)

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 664–666why, one step back
664 prep = req.prepare()
665 session.rebuild_proxies(prep, proxies)666

Fix linting issuesNate Prewittbefore adoption6e5b15d

line 667why, one step back
667 assert ("Proxy-Authorization" in prep.headers) is has_proxy_auth

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

line 668why, one step back
668

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 669why, one step back
669 def test_basicauth_with_netrc(self, httpbin):

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

lines 670–673why, one step back
670 auth = ("user", "pass")
671 wrong_auth = ("wronguser", "wrongpass")672 url = httpbin("basic-auth", "user", "pass")673

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 674why, one step back
674 old_auth = requests.sessions.get_netrc_auth

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

lines 675–677why, one step back
675
676 try:677

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 678–679why, one step back
678 def get_netrc_auth_mock(url):
679 return auth

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

line 680why, one step back
680

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 681why, one step back
681 requests.sessions.get_netrc_auth = get_netrc_auth_mock

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

lines 682–687why, one step back
682
683 # Should use netrc and work.684 r = requests.get(url)685 assert r.status_code == 200686687 # Given auth should override and fail.

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 688why, one step back
688 r = requests.get(url, auth=wrong_auth)

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

lines 689–697why, one step back
689 assert r.status_code == 401
690691 s = requests.session()692693 # Should use netrc and work.694 r = s.get(url)695 assert r.status_code == 200696697 # Given auth should override and fail.

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 698why, one step back
698 s.auth = wrong_auth

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

lines 699–700why, one step back
699 r = s.get(url)
700 assert r.status_code == 401

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 701–702why, one step back
701 finally:
702 requests.sessions.get_netrc_auth = old_auth

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

line 703why, one step back
703

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 704why, one step back
704 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):

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

lines 705–720why, one step back
705 for authtype in self.digest_auth_algo:
706 auth = HTTPDigestAuth("user", "pass")707 url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")708709 r = requests.get(url, auth=auth)710 assert r.status_code == 200711712 r = requests.get(url)713 assert r.status_code == 401714 print(r.headers["WWW-Authenticate"])715716 s = requests.session()717 s.auth = HTTPDigestAuth("user", "pass")718 r = s.get(url)719 assert r.status_code == 200720

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 721why, one step back
721 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):

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

lines 722–730why, one step back
722 for authtype in self.digest_auth_algo:
723 url = httpbin("digest-auth", "auth", "user", "pass", authtype)724 auth = HTTPDigestAuth("user", "pass")725 r = requests.get(url)726 assert r.cookies["fake"] == "fake_value"727728 r = requests.get(url, auth=auth)729 assert r.status_code == 200730

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 731why, one step back
731 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):

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

lines 732–734why, one step back
732 for authtype in self.digest_auth_algo:
733 url = httpbin("digest-auth", "auth", "user", "pass", authtype)734 auth = HTTPDigestAuth("user", "pass")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 735–736why, one step back
735 s = requests.Session()
736 s.get(url, auth=auth)

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

lines 737–738why, one step back
737 assert s.cookies["fake"] == "fake_value"
738

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 739why, one step back
739 def test_DIGEST_STREAM(self, httpbin):

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

lines 740–743why, one step back
740 for authtype in self.digest_auth_algo:
741 auth = HTTPDigestAuth("user", "pass")742 url = httpbin("digest-auth", "auth", "user", "pass", authtype)743

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 744why, one step back
744 r = requests.get(url, auth=auth, stream=True)

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

lines 745–746why, one step back
745 assert r.raw.read() != b""
746

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 747why, one step back
747 r = requests.get(url, auth=auth, stream=False)

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

lines 748–749why, one step back
748 assert r.raw.read() == b""
749

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 750why, one step back
750 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):

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

lines 751–761why, one step back
751 for authtype in self.digest_auth_algo:
752 auth = HTTPDigestAuth("user", "wrongpass")753 url = httpbin("digest-auth", "auth", "user", "pass", authtype)754755 r = requests.get(url, auth=auth)756 assert r.status_code == 401757758 r = requests.get(url)759 assert r.status_code == 401760761 s = requests.session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 762why, one step back
762 s.auth = auth

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

lines 763–765why, one step back
763 r = s.get(url)
764 assert r.status_code == 401765

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 766why, one step back
766 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):

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

lines 767–773why, one step back
767 for authtype in self.digest_auth_algo:
768 auth = HTTPDigestAuth("user", "pass")769 url = httpbin("digest-auth", "auth", "user", "pass", authtype)770771 r = requests.get(url, auth=auth)772 assert '"auth"' in r.request.headers["Authorization"]773

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 774why, one step back
774 def test_POSTBIN_GET_POST_FILES(self, httpbin):

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

lines 775–790why, one step back
775 url = httpbin("post")
776 requests.post(url).raise_for_status()777778 post1 = requests.post(url, data={"some": "data"})779 assert post1.status_code == 200780781 with open("requirements-dev.txt") as f:782 post2 = requests.post(url, files={"some": f})783 assert post2.status_code == 200784785 post4 = requests.post(url, data='[{"some": "json"}]')786 assert post4.status_code == 200787788 with pytest.raises(ValueError):789 requests.post(url, files=["bad file data"])790

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 791why, one step back
791 def test_invalid_files_input(self, httpbin):

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

lines 792–793why, one step back
792 url = httpbin("post")
793 post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 794–795why, one step back
794 assert b'name="random-file-1"' not in post.request.body
795 assert b'name="random-file-2"' in post.request.body

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

line 796why, one step back
796

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 797why, one step back
797 def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):

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

lines 798–799why, one step back
798 class TestStream:
799 def __init__(self, data):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 800–802why, one step back
800 self.data = data.encode()
801 self.length = len(self.data)802 self.index = 0

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

lines 803–804why, one step back
803
804 def __len__(self):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 805why, one step back
805 return self.length

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

line 806why, one step back
806

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 807–808why, one step back
807 def read(self, size=None):
808 if size:

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

line 809why, one step back
809 ret = self.data[self.index : self.index + size]

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 810–811why, one step back
810 self.index += size
811 else:

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

line 812why, one step back
812 ret = self.data[self.index :]

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 813–814why, one step back
813 self.index = self.length
814 return ret

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

lines 815–816why, one step back
815
816 def tell(self):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 817why, one step back
817 return self.index

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

line 818why, one step back
818

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 819–825why, one step back
819 def seek(self, offset, where=0):
820 if where == 0:821 self.index = offset822 elif where == 1:823 self.index += offset824 elif where == 2:825 self.index = self.length + offset

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

lines 826–832why, one step back
826
827 test = TestStream("test")828 post1 = requests.post(httpbin("post"), data=test)829 assert post1.status_code == 200830 assert post1.json()["data"] == "test"831832 test = TestStream("test")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 833why, one step back
833 test.seek(2)

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

lines 834–837why, one step back
834 post2 = requests.post(httpbin("post"), data=test)
835 assert post2.status_code == 200836 assert post2.json()["data"] == "st"837

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 838why, one step back
838 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):

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

lines 839–854why, one step back
839 url = httpbin("post")
840 requests.post(url).raise_for_status()841842 post1 = requests.post(url, data={"some": "data"})843 assert post1.status_code == 200844845 with open("requirements-dev.txt") as f:846 post2 = requests.post(url, data={"some": "data"}, files={"some": f})847 assert post2.status_code == 200848849 post4 = requests.post(url, data='[{"some": "json"}]')850 assert post4.status_code == 200851852 with pytest.raises(ValueError):853 requests.post(url, files=["bad file data"])854

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 855–858why, one step back
855 def test_post_with_custom_mapping(self, httpbin):
856 class CustomMapping(MutableMapping):857 def __init__(self, *args, **kwargs):858 self.data = dict(*args, **kwargs)

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

line 859why, one step back
859

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 860–861why, one step back
860 def __delitem__(self, key):
861 del self.data[key]

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

line 862why, one step back
862

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 863–864why, one step back
863 def __getitem__(self, key):
864 return self.data[key]

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

line 865why, one step back
865

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 866–867why, one step back
866 def __setitem__(self, key, value):
867 self.data[key] = value

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

lines 868–869why, one step back
868
869 def __iter__(self):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 870why, one step back
870 return iter(self.data)

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

lines 871–872why, one step back
871
872 def __len__(self):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 873why, one step back
873 return len(self.data)

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

lines 874–879why, one step back
874
875 data = CustomMapping({"some": "data"})876 url = httpbin("post")877 found_json = requests.post(url, data=data).json().get("form")878 assert found_json == {"some": "data"}879

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 880why, one step back
880 def test_conflicting_post_params(self, httpbin):

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

lines 881–882why, one step back
881 url = httpbin("post")
882 with open("requirements-dev.txt") as f:

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 883why, one step back
883 with pytest.raises(ValueError):

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

lines 884–885why, one step back
884 requests.post(url, data='[{"some": "data"}]', files={"some": f})
885

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 886why, one step back
886 def test_request_ok_set(self, httpbin):

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

lines 887–889why, one step back
887 r = requests.get(httpbin("status", "404"))
888 assert not r.ok889

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 890why, one step back
890 def test_status_raising(self, httpbin):

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

line 891why, one step back
891 r = requests.get(httpbin("status", "404"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 892why, one step back
892 with pytest.raises(requests.exceptions.HTTPError):

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

lines 893–897why, one step back
893 r.raise_for_status()
894895 r = requests.get(httpbin("status", "500"))896 assert not r.ok897

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 898why, one step back
898 def test_decompress_gzip(self, httpbin):

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

lines 899–911why, one step back
899 r = requests.get(httpbin("gzip"))
900 r.content.decode("ascii")901902 @pytest.mark.parametrize(903 "url, params",904 (905 ("/get", {"foo": "føø"}),906 ("/get", {"føø": "føø"}),907 ("/get", {"føø": "føø"}),908 ("/get", {"foo": "foo"}),909 ("ø", {"foo": "foo"}),910 ),911 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 912–913why, one step back
912 def test_unicode_get(self, httpbin, url, params):
913 requests.get(httpbin(url), params=params)

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

line 914why, one step back
914

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 915–916why, one step back
915 def test_unicode_header_name(self, httpbin):
916 requests.put(

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

lines 917–921why, one step back
917 httpbin("put"),
918 headers={"Content-Type": "application/octet-stream"},919 data="\xff",920 ) # compat.str is unicode.921

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 922why, one step back
922 def test_pyopenssl_redirect(self, httpbin_secure, httpbin_ca_bundle):

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

lines 923–924why, one step back
923 requests.get(httpbin_secure("status", "301"), verify=httpbin_ca_bundle)
924

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 925why, one step back
925 def test_invalid_ca_certificate_path(self, httpbin_secure):

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

lines 926–927why, one step back
926 INVALID_PATH = "/garbage"
927 with pytest.raises(IOError) as e:

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 928why, one step back
928 requests.get(httpbin_secure(), verify=INVALID_PATH)

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

lines 929–934why, one step back
929 assert str(
930 e.value931 ) == "Could not find a suitable TLS CA certificate bundle, invalid path: {}".format(932 INVALID_PATH933 )934

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 935why, one step back
935 def test_invalid_ssl_certificate_files(self, httpbin_secure):

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

lines 936–937why, one step back
936 INVALID_PATH = "/garbage"
937 with pytest.raises(IOError) as e:

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 938why, one step back
938 requests.get(httpbin_secure(), cert=INVALID_PATH)

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

lines 939–953why, one step back
939 assert str(
940 e.value941 ) == "Could not find the TLS certificate file, invalid path: {}".format(942 INVALID_PATH943 )944945 with pytest.raises(IOError) as e:946 requests.get(httpbin_secure(), cert=(".", INVALID_PATH))947 assert str(e.value) == (948 f"Could not find the TLS key file, invalid path: {INVALID_PATH}"949 )950951 @pytest.mark.parametrize(952 "env, expected",953 (

Merge pull request #6074 from nateprewitt/curl_ca_bundleIan Stapleton Cordascobefore adoption79f6027

line 954why, one step back
954 ({}, True),

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

lines 955–975why, one step back
955 ({"REQUESTS_CA_BUNDLE": "/some/path"}, "/some/path"),
956 ({"REQUESTS_CA_BUNDLE": ""}, True),957 ({"CURL_CA_BUNDLE": "/some/path"}, "/some/path"),958 ({"CURL_CA_BUNDLE": ""}, True),959 ({"REQUESTS_CA_BUNDLE": "", "CURL_CA_BUNDLE": ""}, True),960 (961 {962 "REQUESTS_CA_BUNDLE": "/some/path",963 "CURL_CA_BUNDLE": "/curl/path",964 },965 "/some/path",966 ),967 (968 {969 "REQUESTS_CA_BUNDLE": "",970 "CURL_CA_BUNDLE": "/curl/path",971 },972 "/curl/path",973 ),974 ),975 )

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

line 976why, one step back
976 def test_env_cert_bundles(self, httpbin, env, expected):

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

line 977why, one step back
977 s = requests.Session()

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

lines 978–981why, one step back
978 with mock.patch("os.environ", env):
979 settings = s.merge_environment_settings(980 url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None981 )

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

lines 982–983why, one step back
982 assert settings["verify"] == expected
983

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 984why, one step back
984 def test_http_with_certificate(self, httpbin):

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

lines 985–987why, one step back
985 r = requests.get(httpbin(), cert=".")
986 assert r.status_code == 200987

Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590

lines 988–991why, one step back
988 @pytest.mark.skipif(
989 SNIMissingWarning is None,990 reason="urllib3 2.0 removed that warning and errors out instead",991 )

Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba

line 992why, one step back
992 def test_https_warnings(self, nosan_server):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 993why, one step back
993 """warnings are emitted with requests.get"""

Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba

line 994why, one step back
994 host, port, ca_bundle = nosan_server

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 995why, one step back
995 if HAS_MODERN_SSL or HAS_PYOPENSSL:

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

lines 996–1003why, one step back
996 warnings_expected = ("SubjectAltNameWarning",)
997 else:998 warnings_expected = (999 "SNIMissingWarning",1000 "InsecurePlatformWarning",1001 "SubjectAltNameWarning",1002 )1003

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1004why, one step back
1004 with pytest.warns(None) as warning_records:

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

lines 1005–1014why, one step back
1005 warnings.simplefilter("always")
1006 requests.get(f"https://localhost:{port}/", verify=ca_bundle)10071008 warning_records = [1009 item1010 for item in warning_records1011 if item.category.__name__ != "ResourceWarning"1012 ]10131014 warnings_category = tuple(item.category.__name__ for item in warning_records)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1015why, one step back
1015 assert warnings_category == warnings_expected

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

line 1016why, one step back
1016

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1017why, one step back
1017 def test_certificate_failure(self, httpbin_secure):

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

line 1018why, one step back
1018 """

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1019why, one step back
1019 When underlying SSL problems occur, an SSLError is raised.

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

line 1020why, one step back
1020 """

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 1021why, one step back
1021 with pytest.raises(RequestsSSLError):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1022–1023why, one step back
1022 # Our local httpbin does not have a trusted CA, so this call will
1023 # fail if we use our default trust bundle.

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

lines 1024–1025why, one step back
1024 requests.get(httpbin_secure("status", "200"))
1025

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1026why, one step back
1026 def test_urlencoded_get_query_multivalued_param(self, httpbin):

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

lines 1027–1030why, one step back
1027 r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})
1028 assert r.status_code == 2001029 assert r.url == httpbin("get?test=foo&test=baz")1030

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1031why, one step back
1031 def test_form_encoded_post_query_multivalued_element(self, httpbin):

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

lines 1032–1037why, one step back
1032 r = requests.Request(
1033 method="POST", url=httpbin("post"), data=dict(test=["foo", "baz"])1034 )1035 prep = r.prepare()1036 assert prep.body == "test=foo&test=baz"1037

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1038why, one step back
1038 def test_different_encodings_dont_break_post(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1039–1045why, one step back
1039 with open(__file__, "rb") as f:
1040 r = requests.post(1041 httpbin("post"),1042 data={"stuff": json.dumps({"a": 123})},1043 params={"blah": "asdf1234"},1044 files={"file": ("test_requests.py", f)},1045 )

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

lines 1046–1056why, one step back
1046 assert r.status_code == 200
10471048 @pytest.mark.parametrize(1049 "data",1050 (1051 {"stuff": "ëlïxr"},1052 {"stuff": "ëlïxr".encode()},1053 {"stuff": "elixr"},1054 {"stuff": b"elixr"},1055 ),1056 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1057why, one step back
1057 def test_unicode_multipart_post(self, httpbin, data):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1058–1063why, one step back
1058 with open(__file__, "rb") as f:
1059 r = requests.post(1060 httpbin("post"),1061 data=data,1062 files={"file": ("test_requests.py", f)},1063 )

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

lines 1064–1065why, one step back
1064 assert r.status_code == 200
1065

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1066why, one step back
1066 def test_unicode_multipart_post_fieldnames(self, httpbin):

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

line 1067why, one step back
1067 filename = os.path.splitext(__file__)[0] + ".py"

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1068–1076why, one step back
1068 with open(filename, "rb") as f:
1069 r = requests.Request(1070 method="POST",1071 url=httpbin("post"),1072 data={b"stuff": "elixr"},1073 files={"file": ("test_requests.py", f)},1074 )1075 prep = r.prepare()1076

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1077why, one step back
1077 assert b'name="stuff"' in prep.body

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

lines 1078–1079why, one step back
1078 assert b"name=\"b'stuff'\"" not in prep.body
1079

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1080why, one step back
1080 def test_unicode_method_name(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1081–1087why, one step back
1081 with open(__file__, "rb") as f:
1082 files = {"file": f}1083 r = requests.request(1084 method="POST",1085 url=httpbin("post"),1086 files=files,1087 )

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

lines 1088–1089why, one step back
1088 assert r.status_code == 200
1089

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1090why, one step back
1090 def test_unicode_method_name_with_request_object(self, httpbin):

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

line 1091why, one step back
1091 s = requests.Session()

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1092–1095why, one step back
1092 with open(__file__, "rb") as f:
1093 files = {"file": f}1094 req = requests.Request("POST", httpbin("post"), files=files)1095 prep = s.prepare_request(req)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1096why, one step back
1096 assert isinstance(prep.method, builtin_str)

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

lines 1097–1101why, one step back
1097 assert prep.method == "POST"
10981099 resp = s.send(prep)1100 assert resp.status_code == 2001101

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1102why, one step back
1102 def test_non_prepared_request_error(self):

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

lines 1103–1106why, one step back
1103 s = requests.Session()
1104 req = requests.Request("POST", "/")11051106 with pytest.raises(ValueError) as e:

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1107why, one step back
1107 s.send(req)

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

lines 1108–1109why, one step back
1108 assert str(e.value) == "You can only send PreparedRequests."
1109

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1110why, one step back
1110 def test_custom_content_type(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1111–1112why, one step back
1111 with open(__file__, "rb") as f1:
1112 with open(__file__, "rb") as f2:

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1113why, one step back
1113 data = {"stuff": json.dumps({"a": 123})}

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1114–1118why, one step back
1114 files = {
1115 "file1": ("test_requests.py", f1),1116 "file2": ("test_requests", f2, "text/py-content-type"),1117 }1118 r = requests.post(httpbin("post"), data=data, files=files)

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

line 1119why, one step back
1119 assert r.status_code == 200

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1120why, one step back
1120 assert b"text/py-content-type" in r.request.body

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

line 1121why, one step back
1121

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1122why, one step back
1122 def test_hook_receives_request_arguments(self, httpbin):

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

line 1123why, one step back
1123 def hook(resp, **kwargs):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1124–1125why, one step back
1124 assert resp is not None
1125 assert kwargs != {}

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

lines 1126–1129why, one step back
1126
1127 s = requests.Session()1128 r = requests.Request("GET", httpbin(), hooks={"response": hook})1129 prep = s.prepare_request(r)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1130why, one step back
1130 s.send(prep)

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

line 1131why, one step back
1131

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1132why, one step back
1132 def test_session_hooks_are_used_with_no_request_hooks(self, httpbin):

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

lines 1133–1142why, one step back
1133 def hook(*args, **kwargs):
1134 pass11351136 s = requests.Session()1137 s.hooks["response"].append(hook)1138 r = requests.Request("GET", httpbin())1139 prep = s.prepare_request(r)1140 assert prep.hooks["response"] != []1141 assert prep.hooks["response"] == [hook]1142

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1143why, one step back
1143 def test_session_hooks_are_overridden_by_request_hooks(self, httpbin):

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

lines 1144–1149why, one step back
1144 def hook1(*args, **kwargs):
1145 pass11461147 def hook2(*args, **kwargs):1148 pass1149

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1150why, one step back
1150 assert hook1 is not hook2

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

lines 1151–1156why, one step back
1151 s = requests.Session()
1152 s.hooks["response"].append(hook2)1153 r = requests.Request("GET", httpbin(), hooks={"response": [hook1]})1154 prep = s.prepare_request(r)1155 assert prep.hooks["response"] == [hook1]1156

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1157why, one step back
1157 def test_prepared_request_hook(self, httpbin):

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

line 1158why, one step back
1158 def hook(resp, **kwargs):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1159why, one step back
1159 resp.hook_working = True

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

lines 1160–1162why, one step back
1160 return resp
11611162 req = requests.Request("GET", httpbin(), hooks={"response": hook})

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1163why, one step back
1163 prep = req.prepare()

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

lines 1164–1170why, one step back
1164
1165 s = requests.Session()1166 s.proxies = getproxies()1167 resp = s.send(prep)11681169 assert hasattr(resp, "hook_working")1170

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1171–1173why, one step back
1171 def test_prepared_from_session(self, httpbin):
1172 class DummyAuth(requests.auth.AuthBase):1173 def __call__(self, r):

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

line 1174why, one step back
1174 r.headers["Dummy-Auth-Test"] = "dummy-auth-test-ok"

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1175why, one step back
1175 return r

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

lines 1176–1177why, one step back
1176
1177 req = requests.Request("GET", httpbin("headers"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1178why, one step back
1178 assert not req.auth

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

lines 1179–1180why, one step back
1179
1180 s = requests.Session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1181why, one step back
1181 s.auth = DummyAuth()

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

lines 1182–1187why, one step back
1182
1183 prep = s.prepare_request(req)1184 resp = s.send(prep)11851186 assert resp.json()["headers"]["Dummy-Auth-Test"] == "dummy-auth-test-ok"1187

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1188why, one step back
1188 def test_prepare_request_with_bytestring_url(self):

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

lines 1189–1191why, one step back
1189 req = requests.Request("GET", b"https://httpbin.org/")
1190 s = requests.Session()1191 prep = s.prepare_request(req)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1192why, one step back
1192 assert prep.url == "https://httpbin.org/"

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

line 1193why, one step back
1193

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1194why, one step back
1194 def test_request_with_bytestring_host(self, httpbin):

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

line 1195why, one step back
1195 s = requests.Session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1196why, one step back
1196 resp = s.request(

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

lines 1197–1198why, one step back
1197 "GET",
1198 httpbin("cookies/set?cookie=value"),

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1199why, one step back
1199 allow_redirects=False,

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

lines 1200–1203why, one step back
1200 headers={"Host": b"httpbin.org"},
1201 )1202 assert resp.cookies.get("cookie") == "value"1203

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1204why, one step back
1204 def test_links(self):

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

line 1205why, one step back
1205 r = requests.Response()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1206why, one step back
1206 r.headers = {

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

lines 1207–1229why, one step back
1207 "cache-control": "public, max-age=60, s-maxage=60",
1208 "connection": "keep-alive",1209 "content-encoding": "gzip",1210 "content-type": "application/json; charset=utf-8",1211 "date": "Sat, 26 Jan 2013 16:47:56 GMT",1212 "etag": '"6ff6a73c0e446c1f61614769e3ceb778"',1213 "last-modified": "Sat, 26 Jan 2013 16:22:39 GMT",1214 "link": (1215 "<https://api.github.com/users/kennethreitz/repos?"1216 'page=2&per_page=10>; rel="next", <https://api.github.'1217 "com/users/kennethreitz/repos?page=7&per_page=10>; "1218 ' rel="last"'1219 ),1220 "server": "GitHub.com",1221 "status": "200 OK",1222 "vary": "Accept",1223 "x-content-type-options": "nosniff",1224 "x-github-media-type": "github.beta",1225 "x-ratelimit-limit": "60",1226 "x-ratelimit-remaining": "57",1227 }1228 assert r.links["next"]["rel"] == "next"1229

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1230why, one step back
1230 def test_cookie_parameters(self):

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

lines 1231–1232why, one step back
1231 key = "some_cookie"
1232 value = "some_value"

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1233why, one step back
1233 secure = True

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

lines 1234–1237why, one step back
1234 domain = "test.com"
1235 rest = {"HttpOnly": True}12361237 jar = requests.cookies.RequestsCookieJar()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1238why, one step back
1238 jar.set(key, value, secure=secure, domain=domain, rest=rest)

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

line 1239why, one step back
1239

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1240why, one step back
1240 assert len(jar) == 1

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

lines 1241–1242why, one step back
1241 assert "some_cookie" in jar
1242

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1243–1245why, one step back
1243 cookie = list(jar)[0]
1244 assert cookie.secure == secure1245 assert cookie.domain == domain

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

lines 1246–1247why, one step back
1246 assert cookie._rest["HttpOnly"] == rest["HttpOnly"]
1247

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1248why, one step back
1248 def test_cookie_as_dict_keeps_len(self):

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

lines 1249–1262why, one step back
1249 key = "some_cookie"
1250 value = "some_value"12511252 key1 = "some_cookie1"1253 value1 = "some_value1"12541255 jar = requests.cookies.RequestsCookieJar()1256 jar.set(key, value)1257 jar.set(key1, value1)12581259 d1 = dict(jar)1260 d2 = dict(jar.iteritems())1261 d3 = dict(jar.items())1262

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1263–1266why, one step back
1263 assert len(jar) == 2
1264 assert len(d1) == 21265 assert len(d2) == 21266 assert len(d3) == 2

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

line 1267why, one step back
1267

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1268why, one step back
1268 def test_cookie_as_dict_keeps_items(self):

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

lines 1269–1286why, one step back
1269 key = "some_cookie"
1270 value = "some_value"12711272 key1 = "some_cookie1"1273 value1 = "some_value1"12741275 jar = requests.cookies.RequestsCookieJar()1276 jar.set(key, value)1277 jar.set(key1, value1)12781279 d1 = dict(jar)1280 d2 = dict(jar.iteritems())1281 d3 = dict(jar.items())12821283 assert d1["some_cookie"] == "some_value"1284 assert d2["some_cookie"] == "some_value"1285 assert d3["some_cookie1"] == "some_value1"1286

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1287why, one step back
1287 def test_cookie_as_dict_keys(self):

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

lines 1288–1297why, one step back
1288 key = "some_cookie"
1289 value = "some_value"12901291 key1 = "some_cookie1"1292 value1 = "some_value1"12931294 jar = requests.cookies.RequestsCookieJar()1295 jar.set(key, value)1296 jar.set(key1, value1)1297

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1298–1301why, one step back
1298 keys = jar.keys()
1299 assert keys == list(keys)1300 # make sure one can use keys multiple times1301 assert list(keys) == list(keys)

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

line 1302why, one step back
1302

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1303why, one step back
1303 def test_cookie_as_dict_values(self):

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

lines 1304–1313why, one step back
1304 key = "some_cookie"
1305 value = "some_value"13061307 key1 = "some_cookie1"1308 value1 = "some_value1"13091310 jar = requests.cookies.RequestsCookieJar()1311 jar.set(key, value)1312 jar.set(key1, value1)1313

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1314–1317why, one step back
1314 values = jar.values()
1315 assert values == list(values)1316 # make sure one can use values multiple times1317 assert list(values) == list(values)

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

line 1318why, one step back
1318

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1319why, one step back
1319 def test_cookie_as_dict_items(self):

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

lines 1320–1330why, one step back
1320 key = "some_cookie"
1321 value = "some_value"13221323 key1 = "some_cookie1"1324 value1 = "some_value1"13251326 jar = requests.cookies.RequestsCookieJar()1327 jar.set(key, value)1328 jar.set(key1, value1)13291330 items = jar.items()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1331–1333why, one step back
1331 assert items == list(items)
1332 # make sure one can use items multiple times1333 assert list(items) == list(items)

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

line 1334why, one step back
1334

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1335why, one step back
1335 def test_cookie_duplicate_names_different_domains(self):

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

lines 1336–1341why, one step back
1336 key = "some_cookie"
1337 value = "some_value"1338 domain1 = "test1.com"1339 domain2 = "test2.com"13401341 jar = requests.cookies.RequestsCookieJar()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1342–1344why, one step back
1342 jar.set(key, value, domain=domain1)
1343 jar.set(key, value, domain=domain2)1344 assert key in jar

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

line 1345why, one step back
1345 items = jar.items()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1346why, one step back
1346 assert len(items) == 2

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

line 1347why, one step back
1347

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1348why, one step back
1348 # Verify that CookieConflictError is raised if domain is not specified

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

lines 1349–1351why, one step back
1349 with pytest.raises(requests.cookies.CookieConflictError):
1350 jar.get(key)1351

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1352–1354why, one step back
1352 # Verify that CookieConflictError is not raised if domain is specified
1353 cookie = jar.get(key, domain=domain1)1354 assert cookie == value

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

line 1355why, one step back
1355

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1356why, one step back
1356 def test_cookie_duplicate_names_raises_cookie_conflict_error(self):

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

lines 1357–1361why, one step back
1357 key = "some_cookie"
1358 value = "some_value"1359 path = "some_path"13601361 jar = requests.cookies.RequestsCookieJar()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1362why, one step back
1362 jar.set(key, value, path=path)

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

lines 1363–1366why, one step back
1363 jar.set(key, value)
1364 with pytest.raises(requests.cookies.CookieConflictError):1365 jar.get(key)1366

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1367–1368why, one step back
1367 def test_cookie_policy_copy(self):
1368 class MyCookiePolicy(cookielib.DefaultCookiePolicy):

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

lines 1369–1371why, one step back
1369 pass
13701371 jar = requests.cookies.RequestsCookieJar()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1372–1373why, one step back
1372 jar.set_policy(MyCookiePolicy())
1373 assert isinstance(jar.copy().get_policy(), MyCookiePolicy)

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

line 1374why, one step back
1374

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1375why, one step back
1375 def test_time_elapsed_blank(self, httpbin):

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

line 1376why, one step back
1376 r = requests.get(httpbin("get"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1377why, one step back
1377 td = r.elapsed

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

lines 1378–1380why, one step back
1378 total_seconds = (
1379 td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**61380 ) / 10**6

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1381why, one step back
1381 assert total_seconds > 0.0

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

line 1382why, one step back
1382

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1383why, one step back
1383 def test_empty_response_has_content_none(self):

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

lines 1384–1386why, one step back
1384 r = requests.Response()
1385 assert r.content is None1386

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1387why, one step back
1387 def test_response_is_iterable(self):

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

lines 1388–1389why, one step back
1388 r = requests.Response()
1389 io = StringIO.StringIO("abc")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1390why, one step back
1390 read_ = io.read

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

line 1391why, one step back
1391

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1392–1393why, one step back
1392 def read_mock(amt, decode_content=None):
1393 return read_(amt)

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

lines 1394–1395why, one step back
1394
1395 setattr(io, "read", read_mock)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1396–1398why, one step back
1396 r.raw = io
1397 assert next(iter(r))1398 io.close()

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

line 1399why, one step back
1399

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1400–1402why, one step back
1400 def test_response_decode_unicode(self):
1401 """When called with decode_unicode, Response.iter_content should always1402 return unicode.

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

lines 1403–1404why, one step back
1403 """
1404 r = requests.Response()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1405why, one step back
1405 r._content_consumed = True

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

lines 1406–1411why, one step back
1406 r._content = b"the content"
1407 r.encoding = "ascii"14081409 chunks = r.iter_content(decode_unicode=True)1410 assert all(isinstance(chunk, str) for chunk in chunks)1411

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1412why, one step back
1412 # also for streaming

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

lines 1413–1418why, one step back
1413 r = requests.Response()
1414 r.raw = io.BytesIO(b"the content")1415 r.encoding = "ascii"1416 chunks = r.iter_content(decode_unicode=True)1417 assert all(isinstance(chunk, str) for chunk in chunks)1418

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1419–1420why, one step back
1419 def test_response_reason_unicode(self):
1420 # check for unicode HTTP status

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

lines 1421–1423why, one step back
1421 r = requests.Response()
1422 r.url = "unicode URL"1423 r.reason = "Komponenttia ei löydy".encode()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1424why, one step back
1424 r.status_code = 404

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

line 1425why, one step back
1425 r.encoding = None

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1426why, one step back
1426 assert not r.ok # old behaviour - crashes here

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

line 1427why, one step back
1427

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1428–1429why, one step back
1428 def test_response_reason_unicode_fallback(self):
1429 # check raise_status falls back to ISO-8859-1

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

lines 1430–1433why, one step back
1430 r = requests.Response()
1431 r.url = "some url"1432 reason = "Komponenttia ei löydy"1433 r.reason = reason.encode("latin-1")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1434why, one step back
1434 r.status_code = 500

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

line 1435why, one step back
1435 r.encoding = None

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1436why, one step back
1436 with pytest.raises(requests.exceptions.HTTPError) as e:

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

line 1437why, one step back
1437 r.raise_for_status()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1438why, one step back
1438 assert reason in e.value.args[0]

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

line 1439why, one step back
1439

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1440–1442why, one step back
1440 def test_response_chunk_size_type(self):
1441 """Ensure that chunk_size is passed as None or an integer, otherwise1442 raise a TypeError.

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

lines 1443–1445why, one step back
1443 """
1444 r = requests.Response()1445 r.raw = io.BytesIO(b"the content")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1446–1447why, one step back
1446 chunks = r.iter_content(1)
1447 assert all(len(chunk) == 1 for chunk in chunks)

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

lines 1448–1450why, one step back
1448
1449 r = requests.Response()1450 r.raw = io.BytesIO(b"the content")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1451why, one step back
1451 chunks = r.iter_content(None)

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

lines 1452–1456why, one step back
1452 assert list(chunks) == [b"the content"]
14531454 r = requests.Response()1455 r.raw = io.BytesIO(b"the content")1456 with pytest.raises(TypeError):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1457why, one step back
1457 chunks = r.iter_content("1024")

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

lines 1458–1461why, one step back
1458
1459 @pytest.mark.parametrize(1460 "exception, args, expected",1461 (

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1462–1463why, one step back
1462 (urllib3.exceptions.ProtocolError, tuple(), ChunkedEncodingError),
1463 (urllib3.exceptions.DecodeError, tuple(), ContentDecodingError),

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

line 1464why, one step back
1464 (urllib3.exceptions.ReadTimeoutError, (None, "", ""), ConnectionError),

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 1465why, one step back
1465 (urllib3.exceptions.SSLError, tuple(), RequestsSSLError),

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

lines 1466–1467why, one step back
1466 ),
1467 )

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

line 1468why, one step back
1468 def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):

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

line 1469why, one step back
1469 r = requests.Response()

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

line 1470why, one step back
1470 r.raw = mock.Mock()

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1471–1473why, one step back
1471 # ReadTimeoutError can't be initialized by mock
1472 # so we'll manually create the instance with args1473 r.raw.stream.side_effect = exception(*args)

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

line 1474why, one step back
1474

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1475–1476why, one step back
1475 with pytest.raises(expected):
1476 next(r.iter_content(1024))

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

line 1477why, one step back
1477

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1478why, one step back
1478 def test_request_and_response_are_pickleable(self, httpbin):

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

lines 1479–1480why, one step back
1479 r = requests.get(httpbin("get"))
1480

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1481–1482why, one step back
1481 # verify we can pickle the original request
1482 assert pickle.loads(pickle.dumps(r.request))

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

line 1483why, one step back
1483

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1484–1488why, one step back
1484 # verify we can pickle the response and that we have access to
1485 # the original request.1486 pr = pickle.loads(pickle.dumps(r))1487 assert r.request.url == pr.request.url1488 assert r.request.headers == pr.request.headers

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

line 1489why, one step back
1489

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1490why, one step back
1490 def test_prepared_request_is_pickleable(self, httpbin):

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

lines 1491–1503why, one step back
1491 p = requests.Request("GET", httpbin("get")).prepare()
14921493 # Verify PreparedRequest can be pickled and unpickled1494 r = pickle.loads(pickle.dumps(p))1495 assert r.url == p.url1496 assert r.headers == p.headers1497 assert r.body == p.body14981499 # Verify unpickled PreparedRequest sends properly1500 s = requests.Session()1501 resp = s.send(r)1502 assert resp.status_code == 2001503

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1504why, one step back
1504 def test_prepared_request_with_file_is_pickleable(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1505–1507why, one step back
1505 with open(__file__, "rb") as f:
1506 r = requests.Request("POST", httpbin("post"), files={"file": f})1507 p = r.prepare()

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

lines 1508–1519why, one step back
1508
1509 # Verify PreparedRequest can be pickled and unpickled1510 r = pickle.loads(pickle.dumps(p))1511 assert r.url == p.url1512 assert r.headers == p.headers1513 assert r.body == p.body15141515 # Verify unpickled PreparedRequest sends properly1516 s = requests.Session()1517 resp = s.send(r)1518 assert resp.status_code == 2001519

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1520why, one step back
1520 def test_prepared_request_with_hook_is_pickleable(self, httpbin):

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

lines 1521–1523why, one step back
1521 r = requests.Request("GET", httpbin("get"), hooks=default_hooks())
1522 p = r.prepare()1523

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1524why, one step back
1524 # Verify PreparedRequest can be pickled

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

lines 1525–1528why, one step back
1525 r = pickle.loads(pickle.dumps(p))
1526 assert r.url == p.url1527 assert r.headers == p.headers1528 assert r.body == p.body

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1529why, one step back
1529 assert r.hooks == p.hooks

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

lines 1530–1535why, one step back
1530
1531 # Verify unpickled PreparedRequest sends properly1532 s = requests.Session()1533 resp = s.send(r)1534 assert resp.status_code == 2001535

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1536–1537why, one step back
1536 def test_cannot_send_unprepared_requests(self, httpbin):
1537 r = requests.Request(url=httpbin())

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

line 1538why, one step back
1538 with pytest.raises(ValueError):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1539why, one step back
1539 requests.Session().send(r)

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

line 1540why, one step back
1540

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1541–1545why, one step back
1541 def test_http_error(self):
1542 error = requests.exceptions.HTTPError()1543 assert not error.response1544 response = requests.Response()1545 error = requests.exceptions.HTTPError(response=response)

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

lines 1546–1550why, one step back
1546 assert error.response == response
1547 error = requests.exceptions.HTTPError("message", response=response)1548 assert str(error) == "message"1549 assert error.response == response1550

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1551why, one step back
1551 def test_session_pickling(self, httpbin):

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

lines 1552–1554why, one step back
1552 r = requests.Request("GET", httpbin("get"))
1553 s = requests.Session()1554

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1555why, one step back
1555 s = pickle.loads(pickle.dumps(s))

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

lines 1556–1560why, one step back
1556 s.proxies = getproxies()
15571558 r = s.send(r.prepare())1559 assert r.status_code == 2001560

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1561–1562why, one step back
1561 def test_fixes_1329(self, httpbin):
1562 """Ensure that header updates are done case-insensitively."""

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

lines 1563–1566why, one step back
1563 s = requests.Session()
1564 s.headers.update({"ACCEPT": "BOGUS"})1565 s.headers.update({"accept": "application/json"})1566 r = s.get(httpbin("get"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1567why, one step back
1567 headers = r.request.headers

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

lines 1568–1571why, one step back
1568 assert headers["accept"] == "application/json"
1569 assert headers["Accept"] == "application/json"1570 assert headers["ACCEPT"] == "application/json"1571

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1572why, one step back
1572 def test_uppercase_scheme_redirect(self, httpbin):

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

line 1573why, one step back
1573 parts = urlparse(httpbin("html"))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1574why, one step back
1574 url = "HTTP://" + parts.netloc + parts.path

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

lines 1575–1576why, one step back
1575 r = requests.get(httpbin("redirect-to"), params={"url": url})
1576 assert r.status_code == 200

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1577why, one step back
1577 assert r.url.lower() == url.lower()

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

line 1578why, one step back
1578

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1579why, one step back
1579 def test_transport_adapter_ordering(self):

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

lines 1580–1610why, one step back
1580 s = requests.Session()
1581 order = ["https://", "http://"]1582 assert order == list(s.adapters)1583 s.mount("http://git", HTTPAdapter())1584 s.mount("http://github", HTTPAdapter())1585 s.mount("http://github.com", HTTPAdapter())1586 s.mount("http://github.com/about/", HTTPAdapter())1587 order = [1588 "http://github.com/about/",1589 "http://github.com",1590 "http://github",1591 "http://git",1592 "https://",1593 "http://",1594 ]1595 assert order == list(s.adapters)1596 s.mount("http://gittip", HTTPAdapter())1597 s.mount("http://gittip.com", HTTPAdapter())1598 s.mount("http://gittip.com/about/", HTTPAdapter())1599 order = [1600 "http://github.com/about/",1601 "http://gittip.com/about/",1602 "http://github.com",1603 "http://gittip.com",1604 "http://github",1605 "http://gittip",1606 "http://git",1607 "https://",1608 "http://",1609 ]1610 assert order == list(s.adapters)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1611why, one step back
1611 s2 = requests.Session()

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

lines 1612–1616why, one step back
1612 s2.adapters = {"http://": HTTPAdapter()}
1613 s2.mount("https://", HTTPAdapter())1614 assert "http://" in s2.adapters1615 assert "https://" in s2.adapters1616

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1617why, one step back
1617 def test_session_get_adapter_prefix_matching(self):

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

lines 1618–1625why, one step back
1618 prefix = "https://example.com"
1619 more_specific_prefix = prefix + "/some/path"16201621 url_matching_only_prefix = prefix + "/another/path"1622 url_matching_more_specific_prefix = more_specific_prefix + "/longer/path"1623 url_not_matching_prefix = "https://another.example.com/"16241625 s = requests.Session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1626–1629why, one step back
1626 prefix_adapter = HTTPAdapter()
1627 more_specific_prefix_adapter = HTTPAdapter()1628 s.mount(prefix, prefix_adapter)1629 s.mount(more_specific_prefix, more_specific_prefix_adapter)

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

line 1630why, one step back
1630

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1631why, one step back
1631 assert s.get_adapter(url_matching_only_prefix) is prefix_adapter

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

lines 1632–1640why, one step back
1632 assert (
1633 s.get_adapter(url_matching_more_specific_prefix)1634 is more_specific_prefix_adapter1635 )1636 assert s.get_adapter(url_not_matching_prefix) not in (1637 prefix_adapter,1638 more_specific_prefix_adapter,1639 )1640

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1641why, one step back
1641 def test_session_get_adapter_prefix_matching_mixed_case(self):

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

lines 1642–1648why, one step back
1642 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"
1643 url_matching_prefix = mixed_case_prefix + "/full_url"16441645 s = requests.Session()1646 my_adapter = HTTPAdapter()1647 s.mount(mixed_case_prefix, my_adapter)1648

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1649why, one step back
1649 assert s.get_adapter(url_matching_prefix) is my_adapter

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

line 1650why, one step back
1650

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1651why, one step back
1651 def test_session_get_adapter_prefix_matching_is_case_insensitive(self):

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

lines 1652–1660why, one step back
1652 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"
1653 url_matching_prefix_with_different_case = (1654 "HtTpS://exaMPLe.cOm/MiXeD_caSE_preFIX/another_url"1655 )16561657 s = requests.Session()1658 my_adapter = HTTPAdapter()1659 s.mount(mixed_case_prefix, my_adapter)1660

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1661why, one step back
1661 assert s.get_adapter(url_matching_prefix_with_different_case) is my_adapter

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

line 1662why, one step back
1662

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1663–1664why, one step back
1663 def test_header_remove_is_case_insensitive(self, httpbin):
1664 # From issue #1321

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

lines 1665–1669why, one step back
1665 s = requests.Session()
1666 s.headers["foo"] = "bar"1667 r = s.get(httpbin("get"), headers={"FOO": None})1668 assert "foo" not in r.request.headers1669

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1670why, one step back
1670 def test_params_are_merged_case_sensitive(self, httpbin):

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

lines 1671–1675why, one step back
1671 s = requests.Session()
1672 s.params["foo"] = "bar"1673 r = s.get(httpbin("get"), params={"FOO": "bar"})1674 assert r.json()["args"] == {"foo": "bar", "FOO": "bar"}1675

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1676why, one step back
1676 def test_long_authinfo_in_url(self):

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

lines 1677–1682why, one step back
1677 url = "http://{}:{}@{}:9000/path?query#frag".format(
1678 "E8A3BE87-9E3F-4620-8858-95478E385B5B",1679 "EA770032-DA4D-4D84-8CE9-29C6D910BF1E",1680 "exactly-------------sixty-----------three------------characters",1681 )1682 r = requests.Request("GET", url).prepare()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1683why, one step back
1683 assert r.url == url

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

line 1684why, one step back
1684

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1685why, one step back
1685 def test_header_keys_are_native(self, httpbin):

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

lines 1686–1689why, one step back
1686 headers = {"unicode": "blah", b"byte": "blah"}
1687 r = requests.Request("GET", httpbin("get"), headers=headers)1688 p = r.prepare()1689

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1690–1691why, one step back
1690 # This is testing that they are builtin strings. A bit weird, but there
1691 # we go.

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

lines 1692–1694why, one step back
1692 assert "unicode" in p.headers.keys()
1693 assert "byte" in p.headers.keys()1694

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1695–1696why, one step back
1695 def test_header_validation(self, httpbin):
1696 """Ensure prepare_headers regex isn't flagging valid header contents."""

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1697why, one step back
1697 valid_headers = {

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

lines 1698–1702why, one step back
1698 "foo": "bar baz qux",
1699 "bar": b"fbbq",1700 "baz": "",1701 "qux": "1",1702 }

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1703–1704why, one step back
1703 r = requests.get(httpbin("get"), headers=valid_headers)
1704 for key in valid_headers.keys():

Merge pull request #6552 from swims-hjkl/issue/test_header_validationNate Prewittbefore adoption839a8ed

line 1705why, one step back
1705 assert valid_headers[key] == r.request.headers[key]

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

line 1706why, one step back
1706

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1707–1715why, one step back
1707 @pytest.mark.parametrize(
1708 "invalid_header, key",1709 (1710 ({"foo": 3}, "foo"),1711 ({"bar": {"foo": "bar"}}, "bar"),1712 ({"baz": ["foo", "bar"]}, "baz"),1713 ),1714 )1715 def test_header_value_not_str(self, httpbin, invalid_header, key):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1716–1717why, one step back
1716 """Ensure the header value is of type string or bytes as
1717 per discussion in GH issue #3386

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

lines 1718–1719why, one step back
1718 """
1719 with pytest.raises(InvalidHeader) as excinfo:

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1720–1721why, one step back
1720 requests.get(httpbin("get"), headers=invalid_header)
1721 assert key in str(excinfo.value)

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

line 1722why, one step back
1722

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1723–1736why, one step back
1723 @pytest.mark.parametrize(
1724 "invalid_header",1725 (1726 {"foo": "bar\r\nbaz: qux"},1727 {"foo": "bar\n\rbaz: qux"},1728 {"foo": "bar\nbaz: qux"},1729 {"foo": "bar\rbaz: qux"},1730 {"fo\ro": "bar"},1731 {"fo\r\no": "bar"},1732 {"fo\n\ro": "bar"},1733 {"fo\no": "bar"},1734 ),1735 )1736 def test_header_no_return_chars(self, httpbin, invalid_header):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1737–1738why, one step back
1737 """Ensure that a header containing return character sequences raise an
1738 exception. Otherwise, multiple headers are created from single string.

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

lines 1739–1740why, one step back
1739 """
1740 with pytest.raises(InvalidHeader):

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1741why, one step back
1741 requests.get(httpbin("get"), headers=invalid_header)

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

line 1742why, one step back
1742

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1743–1755why, one step back
1743 @pytest.mark.parametrize(
1744 "invalid_header",1745 (1746 {" foo": "bar"},1747 {"\tfoo": "bar"},1748 {" foo": "bar"},1749 {"foo": " bar"},1750 {"foo": " bar"},1751 {"foo": "\tbar"},1752 {" ": "bar"},1753 ),1754 )1755 def test_header_no_leading_space(self, httpbin, invalid_header):

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1756–1757why, one step back
1756 """Ensure headers containing leading whitespace raise
1757 InvalidHeader Error before sending.

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

lines 1758–1759why, one step back
1758 """
1759 with pytest.raises(InvalidHeader):

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1760why, one step back
1760 requests.get(httpbin("get"), headers=invalid_header)

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

line 1761why, one step back
1761

Allow str/bytes subclasses to be used as header partsSeth Michael Larsonbefore adoption7f694b7

lines 1762–1786why, one step back
1762 def test_header_with_subclass_types(self, httpbin):
1763 """If the subclasses does not behave *exactly* like1764 the base bytes/str classes, this is not supported.1765 This test is for backwards compatibility.1766 """17671768 class MyString(str):1769 pass17701771 class MyBytes(bytes):1772 pass17731774 r_str = requests.get(httpbin("get"), headers={MyString("x-custom"): "myheader"})1775 assert r_str.request.headers["x-custom"] == "myheader"17761777 r_bytes = requests.get(1778 httpbin("get"), headers={MyBytes(b"x-custom"): b"myheader"}1779 )1780 assert r_bytes.request.headers["x-custom"] == b"myheader"17811782 r_mixed = requests.get(1783 httpbin("get"), headers={MyString("x-custom"): MyBytes(b"myheader")}1784 )1785 assert r_mixed.request.headers["x-custom"] == b"myheader"1786

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

line 1787why, one step back
1787 @pytest.mark.parametrize("files", ("foo", b"foo", bytearray(b"foo")))

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1788why, one step back
1788 def test_can_send_objects_with_files(self, httpbin, files):

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

lines 1789–1794why, one step back
1789 data = {"a": "this is a string"}
1790 files = {"b": files}1791 r = requests.Request("POST", httpbin("post"), data=data, files=files)1792 p = r.prepare()1793 assert "multipart/form-data" in p.headers["Content-Type"]1794

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1795–1797why, one step back
1795 def test_can_send_file_object_with_non_string_filename(self, httpbin):
1796 f = io.BytesIO()1797 f.name = 2

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

lines 1798–1802why, one step back
1798 r = requests.Request("POST", httpbin("post"), files={"f": f})
1799 p = r.prepare()18001801 assert "multipart/form-data" in p.headers["Content-Type"]1802

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1803why, one step back
1803 def test_autoset_header_values_are_native(self, httpbin):

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

lines 1804–1806why, one step back
1804 data = "this is a string"
1805 length = "16"1806 req = requests.Request("POST", httpbin("post"), data=data)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1807why, one step back
1807 p = req.prepare()

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

lines 1808–1810why, one step back
1808
1809 assert p.headers["Content-Length"] == length1810

Merge pull request #6589 from bruceadams/super_len_str_utf-8Ian Stapleton Cordascobefore adoptionb8be93a

lines 1811–1827why, one step back
1811 def test_content_length_for_bytes_data(self, httpbin):
1812 data = "This is a string containing multi-byte UTF-8 ☃️"1813 encoded_data = data.encode("utf-8")1814 length = str(len(encoded_data))1815 req = requests.Request("POST", httpbin("post"), data=encoded_data)1816 p = req.prepare()18171818 assert p.headers["Content-Length"] == length18191820 def test_content_length_for_string_data_counts_bytes(self, httpbin):1821 data = "This is a string containing multi-byte UTF-8 ☃️"1822 length = str(len(data.encode("utf-8")))1823 req = requests.Request("POST", httpbin("post"), data=data)1824 p = req.prepare()18251826 assert p.headers["Content-Length"] == length1827

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1828–1829why, one step back
1828 def test_nonhttp_schemes_dont_check_URLs(self):
1829 test_urls = (

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

lines 1830–1833why, one step back
1830 "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",
1831 "file:///etc/passwd",1832 "magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431",1833 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1834why, one step back
1834 for test_url in test_urls:

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

line 1835why, one step back
1835 req = requests.Request("GET", test_url)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1836–1837why, one step back
1836 preq = req.prepare()
1837 assert test_url == preq.url

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

lines 1838–1850why, one step back
1838
1839 def test_auth_is_stripped_on_http_downgrade(1840 self, httpbin, httpbin_secure, httpbin_ca_bundle1841 ):1842 r = requests.get(1843 httpbin_secure("redirect-to"),1844 params={"url": httpbin("get")},1845 auth=("user", "pass"),1846 verify=httpbin_ca_bundle,1847 )1848 assert r.history[0].request.headers["Authorization"]1849 assert "Authorization" not in r.request.headers1850

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1851why, one step back
1851 def test_auth_is_retained_for_redirect_on_host(self, httpbin):

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

lines 1852–1855why, one step back
1852 r = requests.get(httpbin("redirect/1"), auth=("user", "pass"))
1853 h1 = r.history[0].request.headers["Authorization"]1854 h2 = r.request.headers["Authorization"]1855

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1856why, one step back
1856 assert h1 == h2

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

line 1857why, one step back
1857

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1858why, one step back
1858 def test_should_strip_auth_host_change(self):

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

lines 1859–1863why, one step back
1859 s = requests.Session()
1860 assert s.should_strip_auth(1861 "http://example.com/foo", "http://another.example.com/"1862 )1863

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1864why, one step back
1864 def test_should_strip_auth_http_downgrade(self):

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

lines 1865–1867why, one step back
1865 s = requests.Session()
1866 assert s.should_strip_auth("https://example.com/foo", "http://example.com/bar")1867

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1868why, one step back
1868 def test_should_strip_auth_https_upgrade(self):

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

lines 1869–1878why, one step back
1869 s = requests.Session()
1870 assert not s.should_strip_auth(1871 "http://example.com/foo", "https://example.com/bar"1872 )1873 assert not s.should_strip_auth(1874 "http://example.com:80/foo", "https://example.com/bar"1875 )1876 assert not s.should_strip_auth(1877 "http://example.com/foo", "https://example.com:443/bar"1878 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1879why, one step back
1879 # Non-standard ports should trigger stripping

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

lines 1880–1886why, one step back
1880 assert s.should_strip_auth(
1881 "http://example.com:8080/foo", "https://example.com/bar"1882 )1883 assert s.should_strip_auth(1884 "http://example.com/foo", "https://example.com:8443/bar"1885 )1886

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1887why, one step back
1887 def test_should_strip_auth_port_change(self):

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

lines 1888–1901why, one step back
1888 s = requests.Session()
1889 assert s.should_strip_auth(1890 "http://example.com:1234/foo", "https://example.com:4321/bar"1891 )18921893 @pytest.mark.parametrize(1894 "old_uri, new_uri",1895 (1896 ("https://example.com:443/foo", "https://example.com/bar"),1897 ("http://example.com:80/foo", "http://example.com/bar"),1898 ("https://example.com/foo", "https://example.com:443/bar"),1899 ("http://example.com/foo", "http://example.com:80/bar"),1900 ),1901 )

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1902why, one step back
1902 def test_should_strip_auth_default_port(self, old_uri, new_uri):

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

line 1903why, one step back
1903 s = requests.Session()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1904why, one step back
1904 assert not s.should_strip_auth(old_uri, new_uri)

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

line 1905why, one step back
1905

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1906why, one step back
1906 def test_manual_redirect_with_partial_body_read(self, httpbin):

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

lines 1907–1908why, one step back
1907 s = requests.Session()
1908 r1 = s.get(httpbin("redirect/2"), allow_redirects=False, stream=True)

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1909–1910why, one step back
1909 assert r1.is_redirect
1910 rg = s.resolve_redirects(r1, r1.request, stream=True)

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

line 1911why, one step back
1911

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1912why, one step back
1912 # read only the first eight bytes of the response body,

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

line 1913why, one step back
1913 # then follow the redirect

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1914–1916why, one step back
1914 r1.iter_content(8)
1915 r2 = next(rg)1916 assert r2.is_redirect

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

line 1917why, one step back
1917

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1918why, one step back
1918 # read all of the response via iter_content,

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

line 1919why, one step back
1919 # then follow the redirect

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1920why, one step back
1920 for _ in r2.iter_content():

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

line 1921why, one step back
1921 pass

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

lines 1922–1923why, one step back
1922 r3 = next(rg)
1923 assert not r3.is_redirect

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

line 1924why, one step back
1924

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1925why, one step back
1925 def test_prepare_body_position_non_stream(self):

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

lines 1926–1927why, one step back
1926 data = b"the data"
1927 prep = requests.Request("GET", "http://example.com", data=data).prepare()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1928why, one step back
1928 assert prep._body_position is None

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

line 1929why, one step back
1929

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1930why, one step back
1930 def test_rewind_body(self):

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

lines 1931–1942why, one step back
1931 data = io.BytesIO(b"the data")
1932 prep = requests.Request("GET", "http://example.com", data=data).prepare()1933 assert prep._body_position == 01934 assert prep.body.read() == b"the data"19351936 # the data has all been read1937 assert prep.body.read() == b""19381939 # rewind it back1940 requests.utils.rewind_body(prep)1941 assert prep.body.read() == b"the data"1942

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1943why, one step back
1943 def test_rewind_partially_read_body(self):

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

line 1944why, one step back
1944 data = io.BytesIO(b"the data")

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1945why, one step back
1945 data.read(4) # read some data

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

line 1946why, one step back
1946 prep = requests.Request("GET", "http://example.com", data=data).prepare()

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1947why, one step back
1947 assert prep._body_position == 4

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

lines 1948–1956why, one step back
1948 assert prep.body.read() == b"data"
19491950 # the data has all been read1951 assert prep.body.read() == b""19521953 # rewind it back1954 requests.utils.rewind_body(prep)1955 assert prep.body.read() == b"data"1956

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1957why, one step back
1957 def test_rewind_body_no_seek(self):

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

lines 1958–1976why, one step back
1958 class BadFileObj:
1959 def __init__(self, data):1960 self.data = data19611962 def tell(self):1963 return 019641965 def __iter__(self):1966 return19671968 data = BadFileObj("the data")1969 prep = requests.Request("GET", "http://example.com", data=data).prepare()1970 assert prep._body_position == 019711972 with pytest.raises(UnrewindableBodyError) as e:1973 requests.utils.rewind_body(prep)19741975 assert "Unable to rewind request body" in str(e)1976

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1977why, one step back
1977 def test_rewind_body_failed_seek(self):

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

lines 1978–1984why, one step back
1978 class BadFileObj:
1979 def __init__(self, data):1980 self.data = data19811982 def tell(self):1983 return 01984

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 1985why, one step back
1985 def seek(self, pos, whence=0):

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

lines 1986–1999why, one step back
1986 raise OSError()
19871988 def __iter__(self):1989 return19901991 data = BadFileObj("the data")1992 prep = requests.Request("GET", "http://example.com", data=data).prepare()1993 assert prep._body_position == 019941995 with pytest.raises(UnrewindableBodyError) as e:1996 requests.utils.rewind_body(prep)19971998 assert "error occurred when rewinding request body" in str(e)1999

Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982

line 2000why, one step back
2000 def test_rewind_body_failed_tell(self):

The first 2,000 of 2,839 lines.