Skip to content
Myr

client.py

This file

Path

httpcore/client.py

824 lines · 23.6 KiB · Python

Last changed by

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

History of this file

Take it

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 1–3why, one step back
1import typing
2from types import TracebackType3

Auth (#65)Tom Christiebefore adoption5afa7dd

line 4why, one step back
4from .auth import HTTPBasicAuth

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 5why, one step back
5from .concurrency import AsyncioBackend

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 6–9why, one step back
6from .config import (
7 DEFAULT_MAX_REDIRECTS,8 DEFAULT_POOL_LIMITS,9 DEFAULT_TIMEOUT_CONFIG,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

line 10why, one step back
10 CertTypes,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 11why, one step back
11 PoolLimits,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 12–13why, one step back
12 TimeoutTypes,
13 VerifyTypes,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 14–15why, one step back
14)
15from .dispatch.connection_pool import ConnectionPool

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 16why, one step back
16from .dispatch.threaded import ThreadedDispatcher

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 17why, one step back
17from .exceptions import RedirectBodyUnavailable, RedirectLoop, TooManyRedirects

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 18why, one step back
18from .interfaces import AsyncDispatcher, ConcurrencyBackend, Dispatcher

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 19–20why, one step back
19from .models import (
20 URL,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 21–24why, one step back
21 AsyncRequest,
22 AsyncRequestData,23 AsyncResponse,24 AsyncResponseContent,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 25why, one step back
25 AuthTypes,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

lines 26–27why, one step back
26 Cookies,
27 CookieTypes,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 28why, one step back
28 Headers,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 29–31why, one step back
29 HeaderTypes,
30 QueryParamTypes,31 Request,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 32why, one step back
32 RequestData,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

line 33why, one step back
33 Response,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 34why, one step back
34 ResponseContent,

Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425

lines 35–36why, one step back
35 URLTypes,
36)

Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369

line 37why, one step back
37from .status_codes import codes

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 38–39why, one step back
38
39

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 40why, one step back
40class BaseClient:

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 41–42why, one step back
41 def __init__(
42 self,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 43why, one step back
43 auth: AuthTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 44why, one step back
44 cookies: CookieTypes = None,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 45–47why, one step back
45 verify: VerifyTypes = True,
46 cert: CertTypes = None,47 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,

Truckin' onTom Christiebefore adoption6b60d95

line 48why, one step back
48 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 49why, one step back
49 max_redirects: int = DEFAULT_MAX_REDIRECTS,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 50why, one step back
50 dispatch: typing.Union[AsyncDispatcher, Dispatcher] = None,

Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af

line 51why, one step back
51 backend: ConcurrencyBackend = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 52why, one step back
52 ):

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 53–55why, one step back
53 if backend is None:
54 backend = AsyncioBackend()55

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 56why, one step back
56 if dispatch is None:

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 57why, one step back
57 async_dispatch = ConnectionPool(

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 58–62why, one step back
58 verify=verify,
59 cert=cert,60 timeout=timeout,61 pool_limits=pool_limits,62 backend=backend,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 63–67why, one step back
63 ) # type: AsyncDispatcher
64 elif isinstance(dispatch, Dispatcher):65 async_dispatch = ThreadedDispatcher(dispatch, backend)66 else:67 async_dispatch = dispatch

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 68why, one step back
68

Auth (#65)Tom Christiebefore adoption5afa7dd

line 69why, one step back
69 self.auth = auth

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 70why, one step back
70 self.cookies = Cookies(cookies)

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 71why, one step back
71 self.max_redirects = max_redirects

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 72–73why, one step back
72 self.dispatch = async_dispatch
73 self.concurrency_backend = backend

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 74why, one step back
74

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 75–251why, one step back
75 def merge_cookies(
76 self, cookies: CookieTypes = None77 ) -> typing.Optional[CookieTypes]:78 if cookies or self.cookies:79 merged_cookies = Cookies(self.cookies)80 merged_cookies.update(cookies)81 return merged_cookies82 return cookies8384 async def send(85 self,86 request: AsyncRequest,87 *,88 stream: bool = False,89 auth: AuthTypes = None,90 allow_redirects: bool = True,91 verify: VerifyTypes = None,92 cert: CertTypes = None,93 timeout: TimeoutTypes = None,94 ) -> AsyncResponse:95 if auth is None:96 auth = self.auth9798 url = request.url99 if auth is None and (url.username or url.password):100 auth = HTTPBasicAuth(username=url.username, password=url.password)101102 if auth is not None:103 if isinstance(auth, tuple):104 auth = HTTPBasicAuth(username=auth[0], password=auth[1])105 request = auth(request)106107 response = await self.send_handling_redirects(108 request,109 verify=verify,110 cert=cert,111 timeout=timeout,112 allow_redirects=allow_redirects,113 )114115 if not stream:116 try:117 await response.read()118 finally:119 await response.close()120121 return response122123 async def send_handling_redirects(124 self,125 request: AsyncRequest,126 *,127 cert: CertTypes = None,128 verify: VerifyTypes = None,129 timeout: TimeoutTypes = None,130 allow_redirects: bool = True,131 history: typing.List[AsyncResponse] = None,132 ) -> AsyncResponse:133 if history is None:134 history = []135136 while True:137 # We perform these checks here, so that calls to `response.next()`138 # will raise redirect errors if appropriate.139 if len(history) > self.max_redirects:140 raise TooManyRedirects()141 if request.url in [response.url for response in history]:142 raise RedirectLoop()143144 response = await self.dispatch.send(145 request, verify=verify, cert=cert, timeout=timeout146 )147 assert isinstance(response, AsyncResponse)148 response.history = list(history)149 self.cookies.extract_cookies(response)150 history = [response] + history151 if not response.is_redirect:152 break153154 if allow_redirects:155 request = self.build_redirect_request(request, response)156 else:157158 async def send_next() -> AsyncResponse:159 nonlocal request, response, verify, cert, allow_redirects, timeout, history160 request = self.build_redirect_request(request, response)161 response = await self.send_handling_redirects(162 request,163 allow_redirects=allow_redirects,164 verify=verify,165 cert=cert,166 timeout=timeout,167 history=history,168 )169 return response170171 response.next = send_next # type: ignore172 break173174 return response175176 def build_redirect_request(177 self, request: AsyncRequest, response: AsyncResponse178 ) -> AsyncRequest:179 method = self.redirect_method(request, response)180 url = self.redirect_url(request, response)181 headers = self.redirect_headers(request, url)182 content = self.redirect_content(request, method)183 cookies = self.merge_cookies(request.cookies)184 return AsyncRequest(185 method=method, url=url, headers=headers, data=content, cookies=cookies186 )187188 def redirect_method(self, request: AsyncRequest, response: AsyncResponse) -> str:189 """190 When being redirected we may want to change the method of the request191 based on certain specs or browser behavior.192 """193 method = request.method194195 # https://tools.ietf.org/html/rfc7231#section-6.4.4196 if response.status_code == codes.SEE_OTHER and method != "HEAD":197 method = "GET"198199 # Do what the browsers do, despite standards...200 # Turn 302s into GETs.201 if response.status_code == codes.FOUND and method != "HEAD":202 method = "GET"203204 # If a POST is responded to with a 301, turn it into a GET.205 # This bizarre behaviour is explained in 'requests' issue 1704.206 if response.status_code == codes.MOVED_PERMANENTLY and method == "POST":207 method = "GET"208209 return method210211 def redirect_url(self, request: AsyncRequest, response: AsyncResponse) -> URL:212 """213 Return the URL for the redirect to follow.214 """215 location = response.headers["Location"]216217 url = URL(location, allow_relative=True)218219 # Facilitate relative 'Location' headers, as allowed by RFC 7231.220 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')221 if url.is_relative_url:222 url = url.resolve_with(request.url)223224 # Attach previous fragment if needed (RFC 7231 7.1.2)225 if request.url.fragment and not url.fragment:226 url = url.copy_with(fragment=request.url.fragment)227228 return url229230 def redirect_headers(self, request: AsyncRequest, url: URL) -> Headers:231 """232 Strip Authorization headers when responses are redirected away from233 the origin.234 """235 headers = Headers(request.headers)236 if url.origin != request.url.origin:237 del headers["Authorization"]238 return headers239240 def redirect_content(self, request: AsyncRequest, method: str) -> bytes:241 """242 Return the body that should be used for the redirect request.243 """244 if method != request.method and method == "GET":245 return b""246 if request.is_streaming:247 raise RedirectBodyUnavailable()248 return request.content249250251class AsyncClient(BaseClient):

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 252–253why, one step back
252 async def get(
253 self,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 254why, one step back
254 url: URLTypes,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 255why, one step back
255 *,

query_params -> paramsTom Christiebefore adoptionbb70377

line 256why, one step back
256 params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 257why, one step back
257 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 258why, one step back
258 cookies: CookieTypes = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 259why, one step back
259 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 260why, one step back
260 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 261why, one step back
261 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 262–264why, one step back
262 cert: CertTypes = None,
263 verify: VerifyTypes = None,264 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 265why, one step back
265 ) -> AsyncResponse:

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 266why, one step back
266 return await self.request(

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 267–268why, one step back
267 "GET",
268 url,

query_params -> paramsTom Christiebefore adoptionbb70377

line 269why, one step back
269 params=params,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 270why, one step back
270 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 271why, one step back
271 cookies=cookies,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 272why, one step back
272 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 273why, one step back
273 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 274why, one step back
274 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 275–276why, one step back
275 verify=verify,
276 cert=cert,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 277why, one step back
277 timeout=timeout,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 278–279why, one step back
278 )
279

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 280–283why, one step back
280 async def options(
281 self,282 url: URLTypes,283 *,

query_params -> paramsTom Christiebefore adoptionbb70377

line 284why, one step back
284 params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 285why, one step back
285 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 286why, one step back
286 cookies: CookieTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 287why, one step back
287 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 288why, one step back
288 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 289why, one step back
289 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 290–292why, one step back
290 cert: CertTypes = None,
291 verify: VerifyTypes = None,292 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 293why, one step back
293 ) -> AsyncResponse:

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 294–296why, one step back
294 return await self.request(
295 "OPTIONS",296 url,

query_params -> paramsTom Christiebefore adoptionbb70377

line 297why, one step back
297 params=params,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 298why, one step back
298 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 299why, one step back
299 cookies=cookies,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 300why, one step back
300 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 301why, one step back
301 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 302why, one step back
302 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 303–304why, one step back
303 verify=verify,
304 cert=cert,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 305–311why, one step back
305 timeout=timeout,
306 )307308 async def head(309 self,310 url: URLTypes,311 *,

query_params -> paramsTom Christiebefore adoptionbb70377

line 312why, one step back
312 params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 313why, one step back
313 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 314why, one step back
314 cookies: CookieTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 315why, one step back
315 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 316why, one step back
316 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 317why, one step back
317 allow_redirects: bool = False, #  Note: Differs to usual default.

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 318–320why, one step back
318 cert: CertTypes = None,
319 verify: VerifyTypes = None,320 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 321why, one step back
321 ) -> AsyncResponse:

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 322–324why, one step back
322 return await self.request(
323 "HEAD",324 url,

query_params -> paramsTom Christiebefore adoptionbb70377

line 325why, one step back
325 params=params,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 326why, one step back
326 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 327why, one step back
327 cookies=cookies,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 328why, one step back
328 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 329why, one step back
329 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 330why, one step back
330 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 331–332why, one step back
331 verify=verify,
332 cert=cert,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 333–335why, one step back
333 timeout=timeout,
334 )335

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 336–337why, one step back
336 async def post(
337 self,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 338why, one step back
338 url: URLTypes,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 339why, one step back
339 *,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 340why, one step back
340 data: AsyncRequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 341why, one step back
341 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 342why, one step back
342 params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 343why, one step back
343 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 344why, one step back
344 cookies: CookieTypes = None,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 345why, one step back
345 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 346why, one step back
346 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 347why, one step back
347 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 348–350why, one step back
348 cert: CertTypes = None,
349 verify: VerifyTypes = None,350 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 351why, one step back
351 ) -> AsyncResponse:

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 352–354why, one step back
352 return await self.request(
353 "POST",354 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 355why, one step back
355 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 356why, one step back
356 json=json,

query_params -> paramsTom Christiebefore adoptionbb70377

line 357why, one step back
357 params=params,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 358why, one step back
358 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 359why, one step back
359 cookies=cookies,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 360why, one step back
360 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 361why, one step back
361 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 362why, one step back
362 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 363–364why, one step back
363 verify=verify,
364 cert=cert,

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 365–367why, one step back
365 timeout=timeout,
366 )367

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 368–371why, one step back
368 async def put(
369 self,370 url: URLTypes,371 *,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 372why, one step back
372 data: AsyncRequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 373why, one step back
373 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 374why, one step back
374 params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 375why, one step back
375 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 376why, one step back
376 cookies: CookieTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 377why, one step back
377 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 378why, one step back
378 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 379why, one step back
379 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 380–382why, one step back
380 cert: CertTypes = None,
381 verify: VerifyTypes = None,382 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 383why, one step back
383 ) -> AsyncResponse:

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 384–386why, one step back
384 return await self.request(
385 "PUT",386 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 387why, one step back
387 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 388why, one step back
388 json=json,

query_params -> paramsTom Christiebefore adoptionbb70377

line 389why, one step back
389 params=params,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 390why, one step back
390 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 391why, one step back
391 cookies=cookies,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 392why, one step back
392 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 393why, one step back
393 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 394why, one step back
394 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 395–396why, one step back
395 verify=verify,
396 cert=cert,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 397–403why, one step back
397 timeout=timeout,
398 )399400 async def patch(401 self,402 url: URLTypes,403 *,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 404why, one step back
404 data: AsyncRequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 405why, one step back
405 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 406why, one step back
406 params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 407why, one step back
407 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 408why, one step back
408 cookies: CookieTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 409why, one step back
409 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 410why, one step back
410 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 411why, one step back
411 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 412–414why, one step back
412 cert: CertTypes = None,
413 verify: VerifyTypes = None,414 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 415why, one step back
415 ) -> AsyncResponse:

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 416–418why, one step back
416 return await self.request(
417 "PATCH",418 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 419why, one step back
419 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 420why, one step back
420 json=json,

query_params -> paramsTom Christiebefore adoptionbb70377

line 421why, one step back
421 params=params,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 422why, one step back
422 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 423why, one step back
423 cookies=cookies,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 424why, one step back
424 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 425why, one step back
425 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 426why, one step back
426 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 427–428why, one step back
427 verify=verify,
428 cert=cert,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 429–435why, one step back
429 timeout=timeout,
430 )431432 async def delete(433 self,434 url: URLTypes,435 *,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 436why, one step back
436 data: AsyncRequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 437why, one step back
437 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 438why, one step back
438 params: QueryParamTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 439why, one step back
439 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 440why, one step back
440 cookies: CookieTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 441why, one step back
441 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 442why, one step back
442 auth: AuthTypes = None,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 443why, one step back
443 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 444–446why, one step back
444 cert: CertTypes = None,
445 verify: VerifyTypes = None,446 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 447why, one step back
447 ) -> AsyncResponse:

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 448–450why, one step back
448 return await self.request(
449 "DELETE",450 url,

Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53

line 451why, one step back
451 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 452why, one step back
452 json=json,

query_params -> paramsTom Christiebefore adoptionbb70377

line 453why, one step back
453 params=params,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 454why, one step back
454 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 455why, one step back
455 cookies=cookies,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 456why, one step back
456 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 457why, one step back
457 auth=auth,

Finessing interfaceTom Christiebefore adoptiond7619a9

line 458why, one step back
458 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 459–460why, one step back
459 verify=verify,
460 cert=cert,

Finessing interfaceTom Christiebefore adoptiond7619a9

lines 461–463why, one step back
461 timeout=timeout,
462 )463

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 464–468why, one step back
464 async def request(
465 self,466 method: str,467 url: URLTypes,468 *,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 469why, one step back
469 data: AsyncRequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 470why, one step back
470 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 471why, one step back
471 params: QueryParamTypes = None,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 472why, one step back
472 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 473why, one step back
473 cookies: CookieTypes = None,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 474why, one step back
474 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 475why, one step back
475 auth: AuthTypes = None,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 476why, one step back
476 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 477–479why, one step back
477 cert: CertTypes = None,
478 verify: VerifyTypes = None,479 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 480–481why, one step back
480 ) -> AsyncResponse:
481 request = AsyncRequest(

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

lines 482–484why, one step back
482 method,
483 url,484 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 485why, one step back
485 json=json,

query_params -> paramsTom Christiebefore adoptionbb70377

line 486why, one step back
486 params=params,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

lines 487–488why, one step back
487 headers=headers,
488 cookies=self.merge_cookies(cookies),

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 489–492why, one step back
489 )
490 response = await self.send(491 request,492 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 493why, one step back
493 auth=auth,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 494why, one step back
494 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 495–496why, one step back
495 verify=verify,
496 cert=cert,

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

lines 497–500why, one step back
497 timeout=timeout,
498 )499 return response500

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 501why, one step back
501 async def close(self) -> None:

Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144

line 502why, one step back
502 await self.dispatch.close()

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 503why, one step back
503

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 504why, one step back
504 async def __aenter__(self) -> "AsyncClient":

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

lines 505–513why, one step back
505 return self
506507 async def __aexit__(508 self,509 exc_type: typing.Type[BaseException] = None,510 exc_value: BaseException = None,511 traceback: TracebackType = None,512 ) -> None:513 await self.close()

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 514–515why, one step back
514
515

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 516–523why, one step back
516class Client(BaseClient):
517 def _async_request_data(self, data: RequestData) -> AsyncRequestData:518 """519 If the request data is an bytes iterator then return an async bytes520 iterator onto the request data.521 """522 if isinstance(data, (bytes, dict)):523 return data

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 524why, one step back
524

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 525–528why, one step back
525 # Coerce an iterator into an async iterator, with each item in the
526 # iteration running as a thread-pooled operation.527 assert hasattr(data, "__iter__")528 return self.concurrency_backend.iterate_in_threadpool(data)

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 529why, one step back
529

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 530–538why, one step back
530 def _sync_data(self, data: AsyncResponseContent) -> ResponseContent:
531 if isinstance(data, bytes):532 return data533534 # Coerce an async iterator into an iterator, with each item in the535 # iteration run within the event loop.536 assert hasattr(data, "__aiter__")537 return self.concurrency_backend.iterate(data)538

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 539–544why, one step back
539 def request(
540 self,541 method: str,542 url: URLTypes,543 *,544 data: RequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 545why, one step back
545 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 546why, one step back
546 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 547why, one step back
547 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 548why, one step back
548 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 549why, one step back
549 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 550why, one step back
550 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 551why, one step back
551 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 552–554why, one step back
552 cert: CertTypes = None,
553 verify: VerifyTypes = None,554 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 555–556why, one step back
555 ) -> Response:
556 request = AsyncRequest(

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

lines 557–558why, one step back
557 method,
558 url,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 559why, one step back
559 data=self._async_request_data(data),

Add json interfacesTom Christiebefore adoption5a63d31

line 560why, one step back
560 json=json,

query_params -> paramsTom Christiebefore adoptionbb70377

line 561why, one step back
561 params=params,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 562why, one step back
562 headers=headers,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 563why, one step back
563 cookies=self.merge_cookies(cookies),

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 564why, one step back
564 )

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 565–570why, one step back
565 concurrency_backend = self.concurrency_backend
566567 coroutine = self.send568 args = [request]569 kwargs = dict(570 stream=True,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 571why, one step back
571 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 572why, one step back
572 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 573–574why, one step back
573 verify=verify,
574 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 575–576why, one step back
575 timeout=timeout,
576 )

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 577–603why, one step back
577 async_response = concurrency_backend.run(coroutine, *args, **kwargs)
578579 content = getattr(580 async_response, "_raw_content", getattr(async_response, "_raw_stream", None)581 )582583 sync_content = self._sync_data(content)584585 def sync_on_close() -> None:586 nonlocal concurrency_backend, async_response587 concurrency_backend.run(async_response.on_close)588589 response = Response(590 status_code=async_response.status_code,591 reason_phrase=async_response.reason_phrase,592 protocol=async_response.protocol,593 headers=async_response.headers,594 content=sync_content,595 on_close=sync_on_close,596 request=async_response.request,597 history=async_response.history,598 )599 if not stream:600 try:601 response.read()602 finally:603 response.close()

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 604–609why, one step back
604 return response
605606 def get(607 self,608 url: URLTypes,609 *,

query_params -> paramsTom Christiebefore adoptionbb70377

line 610why, one step back
610 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 611why, one step back
611 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 612why, one step back
612 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 613why, one step back
613 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 614why, one step back
614 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 615why, one step back
615 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 616–618why, one step back
616 cert: CertTypes = None,
617 verify: VerifyTypes = None,618 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 619why, one step back
619 ) -> Response:

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 620–623why, one step back
620 return self.request(
621 "GET",622 url,623 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 624why, one step back
624 cookies=cookies,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 625why, one step back
625 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 626why, one step back
626 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 627why, one step back
627 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 628–629why, one step back
628 verify=verify,
629 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 630–636why, one step back
630 timeout=timeout,
631 )632633 def options(634 self,635 url: URLTypes,636 *,

query_params -> paramsTom Christiebefore adoptionbb70377

line 637why, one step back
637 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 638why, one step back
638 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 639why, one step back
639 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 640why, one step back
640 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 641why, one step back
641 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 642why, one step back
642 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 643–645why, one step back
643 cert: CertTypes = None,
644 verify: VerifyTypes = None,645 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 646why, one step back
646 ) -> Response:

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 647–650why, one step back
647 return self.request(
648 "OPTIONS",649 url,650 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 651why, one step back
651 cookies=cookies,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 652why, one step back
652 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 653why, one step back
653 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 654why, one step back
654 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 655–656why, one step back
655 verify=verify,
656 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 657–663why, one step back
657 timeout=timeout,
658 )659660 def head(661 self,662 url: URLTypes,663 *,

query_params -> paramsTom Christiebefore adoptionbb70377

line 664why, one step back
664 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 665why, one step back
665 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 666why, one step back
666 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 667why, one step back
667 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 668why, one step back
668 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 669why, one step back
669 allow_redirects: bool = False, #  Note: Differs to usual default.

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 670–672why, one step back
670 cert: CertTypes = None,
671 verify: VerifyTypes = None,672 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 673why, one step back
673 ) -> Response:

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 674–677why, one step back
674 return self.request(
675 "HEAD",676 url,677 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 678why, one step back
678 cookies=cookies,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 679why, one step back
679 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 680why, one step back
680 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 681why, one step back
681 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 682–683why, one step back
682 verify=verify,
683 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 684–691why, one step back
684 timeout=timeout,
685 )686687 def post(688 self,689 url: URLTypes,690 *,691 data: RequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 692why, one step back
692 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 693why, one step back
693 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 694why, one step back
694 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 695why, one step back
695 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 696why, one step back
696 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 697why, one step back
697 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 698why, one step back
698 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 699–701why, one step back
699 cert: CertTypes = None,
700 verify: VerifyTypes = None,701 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 702why, one step back
702 ) -> Response:

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 703–706why, one step back
703 return self.request(
704 "POST",705 url,706 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 707why, one step back
707 json=json,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 708why, one step back
708 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 709why, one step back
709 cookies=cookies,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 710why, one step back
710 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 711why, one step back
711 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 712why, one step back
712 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 713–714why, one step back
713 verify=verify,
714 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 715–722why, one step back
715 timeout=timeout,
716 )717718 def put(719 self,720 url: URLTypes,721 *,722 data: RequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 723why, one step back
723 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 724why, one step back
724 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 725why, one step back
725 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 726why, one step back
726 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 727why, one step back
727 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 728why, one step back
728 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 729why, one step back
729 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 730–732why, one step back
730 cert: CertTypes = None,
731 verify: VerifyTypes = None,732 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 733why, one step back
733 ) -> Response:

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 734–737why, one step back
734 return self.request(
735 "PUT",736 url,737 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 738why, one step back
738 json=json,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 739why, one step back
739 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 740why, one step back
740 cookies=cookies,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 741why, one step back
741 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 742why, one step back
742 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 743why, one step back
743 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 744–745why, one step back
744 verify=verify,
745 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 746–753why, one step back
746 timeout=timeout,
747 )748749 def patch(750 self,751 url: URLTypes,752 *,753 data: RequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 754why, one step back
754 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 755why, one step back
755 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 756why, one step back
756 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 757why, one step back
757 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 758why, one step back
758 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 759why, one step back
759 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 760why, one step back
760 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 761–763why, one step back
761 cert: CertTypes = None,
762 verify: VerifyTypes = None,763 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 764why, one step back
764 ) -> Response:

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 765–768why, one step back
765 return self.request(
766 "PATCH",767 url,768 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 769why, one step back
769 json=json,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 770why, one step back
770 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 771why, one step back
771 cookies=cookies,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 772why, one step back
772 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 773why, one step back
773 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 774why, one step back
774 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 775–776why, one step back
775 verify=verify,
776 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 777–784why, one step back
777 timeout=timeout,
778 )779780 def delete(781 self,782 url: URLTypes,783 *,784 data: RequestData = b"",

Add json interfacesTom Christiebefore adoption5a63d31

line 785why, one step back
785 json: typing.Any = None,

query_params -> paramsTom Christiebefore adoptionbb70377

line 786why, one step back
786 params: QueryParamTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 787why, one step back
787 headers: HeaderTypes = None,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 788why, one step back
788 cookies: CookieTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 789why, one step back
789 stream: bool = False,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 790why, one step back
790 auth: AuthTypes = None,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 791why, one step back
791 allow_redirects: bool = True,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 792–794why, one step back
792 cert: CertTypes = None,
793 verify: VerifyTypes = None,794 timeout: TimeoutTypes = None,

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 795why, one step back
795 ) -> Response:

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 796–799why, one step back
796 return self.request(
797 "DELETE",798 url,799 data=data,

Add json interfacesTom Christiebefore adoption5a63d31

line 800why, one step back
800 json=json,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 801why, one step back
801 headers=headers,

Cookie support (#73)Tom Christiebefore adoptionfeae0a8

line 802why, one step back
802 cookies=cookies,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 803why, one step back
803 stream=stream,

Auth (#65)Tom Christiebefore adoption5afa7dd

line 804why, one step back
804 auth=auth,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 805why, one step back
805 allow_redirects=allow_redirects,

Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041

lines 806–807why, one step back
806 verify=verify,
807 cert=cert,

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 808–811why, one step back
808 timeout=timeout,
809 )810811 def close(self) -> None:

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

lines 812–813why, one step back
812 coroutine = self.dispatch.close
813 self.concurrency_backend.run(coroutine)

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

lines 814–824why, one step back
814
815 def __enter__(self) -> "Client":816 return self817818 def __exit__(819 self,820 exc_type: typing.Type[BaseException] = None,821 exc_value: BaseException = None,822 traceback: TracebackType = None,823 ) -> None:824 self.close()