client.py
This file
Path
http3/client.py
886 lines · 25.5 KiB · Python
Last changed by
Include host header directly (#109)Tom Christiebefore adoption5539b69
History of this fileTake it
Support WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
line 1why, one step back1import inspecthttp3 (#86)Tom Christiebefore adoptionc9747aa
lines 2–15why, one step back2import typing3from types import TracebackType45from .auth import HTTPBasicAuth6from .concurrency import AsyncioBackend7from .config import (8 DEFAULT_MAX_REDIRECTS,9 DEFAULT_POOL_LIMITS,10 DEFAULT_TIMEOUT_CONFIG,11 CertTypes,12 PoolLimits,13 TimeoutTypes,14 VerifyTypes,15)Support WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
line 16why, one step back16from .dispatch.asgi import ASGIDispatchhttp3 (#86)Tom Christiebefore adoptionc9747aa
lines 17–18why, one step back17from .dispatch.connection_pool import ConnectionPool18from .dispatch.threaded import ThreadedDispatcherSupport WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
line 19why, one step back19from .dispatch.wsgi import WSGIDispatchhttp3 (#86)Tom Christiebefore adoptionc9747aa
lines 20–35why, one step back20from .exceptions import RedirectBodyUnavailable, RedirectLoop, TooManyRedirects21from .interfaces import AsyncDispatcher, ConcurrencyBackend, Dispatcher22from .models import (23 URL,24 AsyncRequest,25 AsyncRequestData,26 AsyncResponse,27 AsyncResponseContent,28 AuthTypes,29 Cookies,30 CookieTypes,31 Headers,32 HeaderTypes,33 QueryParamTypes,34 Request,35 RequestData,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 36why, one step back36 RequestFiles,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 37–53why, one step back37 Response,38 ResponseContent,39 URLTypes,40)41from .status_codes import codes424344class BaseClient:45 def __init__(46 self,47 auth: AuthTypes = None,48 cookies: CookieTypes = None,49 verify: VerifyTypes = True,50 cert: CertTypes = None,51 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,52 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,53 max_redirects: int = DEFAULT_MAX_REDIRECTS,Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
line 54why, one step back54 base_url: URLTypes = None,http3 (#86)Tom Christiebefore adoptionc9747aa
line 55why, one step back55 dispatch: typing.Union[AsyncDispatcher, Dispatcher] = None,Support WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
line 56why, one step back56 app: typing.Callable = None,Include host header directly (#109)Tom Christiebefore adoption5539b69
line 57why, one step back57 raise_app_exceptions: bool = True,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 58–61why, one step back58 backend: ConcurrencyBackend = None,59 ):60 if backend is None:61 backend = AsyncioBackend()Support WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
lines 62–66why, one step back6263 if app is not None:64 param_count = len(inspect.signature(app).parameters)65 assert param_count in (2, 3)66 if param_count == 2:Include host header directly (#109)Tom Christiebefore adoption5539b69
lines 67–69why, one step back67 dispatch = WSGIDispatch(68 app=app, raise_app_exceptions=raise_app_exceptions69 )Support WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
line 70why, one step back70 else:Include host header directly (#109)Tom Christiebefore adoption5539b69
lines 71–73why, one step back71 dispatch = ASGIDispatch(72 app=app, raise_app_exceptions=raise_app_exceptions73 )http3 (#86)Tom Christiebefore adoptionc9747aa
lines 74–87why, one step back7475 if dispatch is None:76 async_dispatch = ConnectionPool(77 verify=verify,78 cert=cert,79 timeout=timeout,80 pool_limits=pool_limits,81 backend=backend,82 ) # type: AsyncDispatcher83 elif isinstance(dispatch, Dispatcher):84 async_dispatch = ThreadedDispatcher(dispatch, backend)85 else:86 async_dispatch = dispatch87Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
line 88why, one step back88 if base_url is None:Handle early connection closes (#103)Tom Christiebefore adoptionb9c8a15
line 89why, one step back89 self.base_url = URL("", allow_relative=True)Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
lines 90–92why, one step back90 else:91 self.base_url = URL(base_url)92http3 (#86)Tom Christiebefore adoptionc9747aa
lines 93–170why, one step back93 self.auth = auth94 self.cookies = Cookies(cookies)95 self.max_redirects = max_redirects96 self.dispatch = async_dispatch97 self.concurrency_backend = backend9899 def merge_cookies(100 self, cookies: CookieTypes = None101 ) -> typing.Optional[CookieTypes]:102 if cookies or self.cookies:103 merged_cookies = Cookies(self.cookies)104 merged_cookies.update(cookies)105 return merged_cookies106 return cookies107108 async def send(109 self,110 request: AsyncRequest,111 *,112 stream: bool = False,113 auth: AuthTypes = None,114 allow_redirects: bool = True,115 verify: VerifyTypes = None,116 cert: CertTypes = None,117 timeout: TimeoutTypes = None,118 ) -> AsyncResponse:119 if auth is None:120 auth = self.auth121122 url = request.url123 if auth is None and (url.username or url.password):124 auth = HTTPBasicAuth(username=url.username, password=url.password)125126 if auth is not None:127 if isinstance(auth, tuple):128 auth = HTTPBasicAuth(username=auth[0], password=auth[1])129 request = auth(request)130131 response = await self.send_handling_redirects(132 request,133 verify=verify,134 cert=cert,135 timeout=timeout,136 allow_redirects=allow_redirects,137 )138139 if not stream:140 try:141 await response.read()142 finally:143 await response.close()144145 return response146147 async def send_handling_redirects(148 self,149 request: AsyncRequest,150 *,151 cert: CertTypes = None,152 verify: VerifyTypes = None,153 timeout: TimeoutTypes = None,154 allow_redirects: bool = True,155 history: typing.List[AsyncResponse] = None,156 ) -> AsyncResponse:157 if history is None:158 history = []159160 while True:161 # We perform these checks here, so that calls to `response.next()`162 # will raise redirect errors if appropriate.163 if len(history) > self.max_redirects:164 raise TooManyRedirects()165 if request.url in [response.url for response in history]:166 raise RedirectLoop()167168 response = await self.dispatch.send(169 request, verify=verify, cert=cert, timeout=timeout170 )Close redirect responses (#88)Tom Christiebefore adoption3ca9a74
lines 171–175why, one step back171 should_close_response = True172 try:173 assert isinstance(response, AsyncResponse)174 response.history = list(history)175 self.cookies.extract_cookies(response)Tweaks (#89)Tom Christiebefore adoption7c6fb5c
line 176why, one step back176 history = history + [response]http3 (#86)Tom Christiebefore adoptionc9747aa
line 177why, one step back177Close redirect responses (#88)Tom Christiebefore adoption3ca9a74
line 178why, one step back178 if allow_redirects and response.is_redirect:http3 (#86)Tom Christiebefore adoptionc9747aa
line 179why, one step back179 request = self.build_redirect_request(request, response)Close redirect responses (#88)Tom Christiebefore adoption3ca9a74
lines 180–185why, one step back180 else:181 should_close_response = False182 break183 finally:184 if should_close_response:185 await response.close()http3 (#86)Tom Christiebefore adoptionc9747aa
line 186why, one step back186Close redirect responses (#88)Tom Christiebefore adoption3ca9a74
line 187why, one step back187 if response.is_redirect:Multipart support (#90)Tom Christiebefore adoption6a44b05
line 188why, one step back188Close redirect responses (#88)Tom Christiebefore adoption3ca9a74
lines 189–202why, one step back189 async def send_next() -> AsyncResponse:190 nonlocal request, response, verify, cert, allow_redirects, timeout, history191 request = self.build_redirect_request(request, response)192 response = await self.send_handling_redirects(193 request,194 allow_redirects=allow_redirects,195 verify=verify,196 cert=cert,197 timeout=timeout,198 history=history,199 )200 return response201202 response.next = send_next # type: ignorehttp3 (#86)Tom Christiebefore adoptionc9747aa
lines 203–251why, one step back203204 return response205206 def build_redirect_request(207 self, request: AsyncRequest, response: AsyncResponse208 ) -> AsyncRequest:209 method = self.redirect_method(request, response)210 url = self.redirect_url(request, response)211 headers = self.redirect_headers(request, url)212 content = self.redirect_content(request, method)213 cookies = self.merge_cookies(request.cookies)214 return AsyncRequest(215 method=method, url=url, headers=headers, data=content, cookies=cookies216 )217218 def redirect_method(self, request: AsyncRequest, response: AsyncResponse) -> str:219 """220 When being redirected we may want to change the method of the request221 based on certain specs or browser behavior.222 """223 method = request.method224225 # https://tools.ietf.org/html/rfc7231#section-6.4.4226 if response.status_code == codes.SEE_OTHER and method != "HEAD":227 method = "GET"228229 # Do what the browsers do, despite standards...230 # Turn 302s into GETs.231 if response.status_code == codes.FOUND and method != "HEAD":232 method = "GET"233234 # If a POST is responded to with a 301, turn it into a GET.235 # This bizarre behaviour is explained in 'requests' issue 1704.236 if response.status_code == codes.MOVED_PERMANENTLY and method == "POST":237 method = "GET"238239 return method240241 def redirect_url(self, request: AsyncRequest, response: AsyncResponse) -> URL:242 """243 Return the URL for the redirect to follow.244 """245 location = response.headers["Location"]246247 url = URL(location, allow_relative=True)248249 # Facilitate relative 'Location' headers, as allowed by RFC 7231.250 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')251 if url.is_relative_url:Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
line 252why, one step back252 url = request.url.join(url)http3 (#86)Tom Christiebefore adoptionc9747aa
lines 253–369why, one step back253254 # Attach previous fragment if needed (RFC 7231 7.1.2)255 if request.url.fragment and not url.fragment:256 url = url.copy_with(fragment=request.url.fragment)257258 return url259260 def redirect_headers(self, request: AsyncRequest, url: URL) -> Headers:261 """262 Strip Authorization headers when responses are redirected away from263 the origin.264 """265 headers = Headers(request.headers)266 if url.origin != request.url.origin:267 del headers["Authorization"]268 return headers269270 def redirect_content(self, request: AsyncRequest, method: str) -> bytes:271 """272 Return the body that should be used for the redirect request.273 """274 if method != request.method and method == "GET":275 return b""276 if request.is_streaming:277 raise RedirectBodyUnavailable()278 return request.content279280281class AsyncClient(BaseClient):282 async def get(283 self,284 url: URLTypes,285 *,286 params: QueryParamTypes = None,287 headers: HeaderTypes = None,288 cookies: CookieTypes = None,289 stream: bool = False,290 auth: AuthTypes = None,291 allow_redirects: bool = True,292 cert: CertTypes = None,293 verify: VerifyTypes = None,294 timeout: TimeoutTypes = None,295 ) -> AsyncResponse:296 return await self.request(297 "GET",298 url,299 params=params,300 headers=headers,301 cookies=cookies,302 stream=stream,303 auth=auth,304 allow_redirects=allow_redirects,305 verify=verify,306 cert=cert,307 timeout=timeout,308 )309310 async def options(311 self,312 url: URLTypes,313 *,314 params: QueryParamTypes = None,315 headers: HeaderTypes = None,316 cookies: CookieTypes = None,317 stream: bool = False,318 auth: AuthTypes = None,319 allow_redirects: bool = True,320 cert: CertTypes = None,321 verify: VerifyTypes = None,322 timeout: TimeoutTypes = None,323 ) -> AsyncResponse:324 return await self.request(325 "OPTIONS",326 url,327 params=params,328 headers=headers,329 cookies=cookies,330 stream=stream,331 auth=auth,332 allow_redirects=allow_redirects,333 verify=verify,334 cert=cert,335 timeout=timeout,336 )337338 async def head(339 self,340 url: URLTypes,341 *,342 params: QueryParamTypes = None,343 headers: HeaderTypes = None,344 cookies: CookieTypes = None,345 stream: bool = False,346 auth: AuthTypes = None,347 allow_redirects: bool = False, # Note: Differs to usual default.348 cert: CertTypes = None,349 verify: VerifyTypes = None,350 timeout: TimeoutTypes = None,351 ) -> AsyncResponse:352 return await self.request(353 "HEAD",354 url,355 params=params,356 headers=headers,357 cookies=cookies,358 stream=stream,359 auth=auth,360 allow_redirects=allow_redirects,361 verify=verify,362 cert=cert,363 timeout=timeout,364 )365366 async def post(367 self,368 url: URLTypes,369 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 370–371why, one step back370 data: AsyncRequestData = None,371 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 372–386why, one step back372 json: typing.Any = None,373 params: QueryParamTypes = None,374 headers: HeaderTypes = None,375 cookies: CookieTypes = None,376 stream: bool = False,377 auth: AuthTypes = None,378 allow_redirects: bool = True,379 cert: CertTypes = None,380 verify: VerifyTypes = None,381 timeout: TimeoutTypes = None,382 ) -> AsyncResponse:383 return await self.request(384 "POST",385 url,386 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 387why, one step back387 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 388–403why, one step back388 json=json,389 params=params,390 headers=headers,391 cookies=cookies,392 stream=stream,393 auth=auth,394 allow_redirects=allow_redirects,395 verify=verify,396 cert=cert,397 timeout=timeout,398 )399400 async def put(401 self,402 url: URLTypes,403 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 404–405why, one step back404 data: AsyncRequestData = None,405 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 406–420why, one step back406 json: typing.Any = None,407 params: QueryParamTypes = None,408 headers: HeaderTypes = None,409 cookies: CookieTypes = None,410 stream: bool = False,411 auth: AuthTypes = None,412 allow_redirects: bool = True,413 cert: CertTypes = None,414 verify: VerifyTypes = None,415 timeout: TimeoutTypes = None,416 ) -> AsyncResponse:417 return await self.request(418 "PUT",419 url,420 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 421why, one step back421 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 422–437why, one step back422 json=json,423 params=params,424 headers=headers,425 cookies=cookies,426 stream=stream,427 auth=auth,428 allow_redirects=allow_redirects,429 verify=verify,430 cert=cert,431 timeout=timeout,432 )433434 async def patch(435 self,436 url: URLTypes,437 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 438–439why, one step back438 data: AsyncRequestData = None,439 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 440–454why, one step back440 json: typing.Any = None,441 params: QueryParamTypes = None,442 headers: HeaderTypes = None,443 cookies: CookieTypes = None,444 stream: bool = False,445 auth: AuthTypes = None,446 allow_redirects: bool = True,447 cert: CertTypes = None,448 verify: VerifyTypes = None,449 timeout: TimeoutTypes = None,450 ) -> AsyncResponse:451 return await self.request(452 "PATCH",453 url,454 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 455why, one step back455 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 456–471why, one step back456 json=json,457 params=params,458 headers=headers,459 cookies=cookies,460 stream=stream,461 auth=auth,462 allow_redirects=allow_redirects,463 verify=verify,464 cert=cert,465 timeout=timeout,466 )467468 async def delete(469 self,470 url: URLTypes,471 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 472–473why, one step back472 data: AsyncRequestData = None,473 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 474–488why, one step back474 json: typing.Any = None,475 params: QueryParamTypes = None,476 headers: HeaderTypes = None,477 cookies: CookieTypes = None,478 stream: bool = False,479 auth: AuthTypes = None,480 allow_redirects: bool = True,481 cert: CertTypes = None,482 verify: VerifyTypes = None,483 timeout: TimeoutTypes = None,484 ) -> AsyncResponse:485 return await self.request(486 "DELETE",487 url,488 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 489why, one step back489 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 490–506why, one step back490 json=json,491 params=params,492 headers=headers,493 cookies=cookies,494 stream=stream,495 auth=auth,496 allow_redirects=allow_redirects,497 verify=verify,498 cert=cert,499 timeout=timeout,500 )501502 async def request(503 self,504 method: str,505 url: URLTypes,506 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 507–508why, one step back507 data: AsyncRequestData = None,508 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 509–519why, one step back509 json: typing.Any = None,510 params: QueryParamTypes = None,511 headers: HeaderTypes = None,512 cookies: CookieTypes = None,513 stream: bool = False,514 auth: AuthTypes = None,515 allow_redirects: bool = True,516 cert: CertTypes = None,517 verify: VerifyTypes = None,518 timeout: TimeoutTypes = None,519 ) -> AsyncResponse:Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
lines 520–521why, one step back520 url = self.base_url.join(url)521 cookies = self.merge_cookies(cookies)http3 (#86)Tom Christiebefore adoptionc9747aa
lines 522–525why, one step back522 request = AsyncRequest(523 method,524 url,525 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 526why, one step back526 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 527–529why, one step back527 json=json,528 params=params,529 headers=headers,Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
line 530why, one step back530 cookies=cookies,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 531–558why, one step back531 )532 response = await self.send(533 request,534 stream=stream,535 auth=auth,536 allow_redirects=allow_redirects,537 verify=verify,538 cert=cert,539 timeout=timeout,540 )541 return response542543 async def close(self) -> None:544 await self.dispatch.close()545546 async def __aenter__(self) -> "AsyncClient":547 return self548549 async def __aexit__(550 self,551 exc_type: typing.Type[BaseException] = None,552 exc_value: BaseException = None,553 traceback: TracebackType = None,554 ) -> None:555 await self.close()556557558class Client(BaseClient):Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 559–561why, one step back559 def _async_request_data(560 self, data: RequestData = None561 ) -> typing.Optional[AsyncRequestData]:http3 (#86)Tom Christiebefore adoptionc9747aa
lines 562–565why, one step back562 """563 If the request data is an bytes iterator then return an async bytes564 iterator onto the request data.565 """Include host header directly (#109)Tom Christiebefore adoption5539b69
line 566why, one step back566 if data is None or isinstance(data, (str, bytes, dict)):http3 (#86)Tom Christiebefore adoptionc9747aa
lines 567–587why, one step back567 return data568569 # Coerce an iterator into an async iterator, with each item in the570 # iteration running as a thread-pooled operation.571 assert hasattr(data, "__iter__")572 return self.concurrency_backend.iterate_in_threadpool(data)573574 def _sync_data(self, data: AsyncResponseContent) -> ResponseContent:575 if isinstance(data, bytes):576 return data577578 # Coerce an async iterator into an iterator, with each item in the579 # iteration run within the event loop.580 assert hasattr(data, "__aiter__")581 return self.concurrency_backend.iterate(data)582583 def request(584 self,585 method: str,586 url: URLTypes,587 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 588–589why, one step back588 data: RequestData = None,589 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 590–600why, one step back590 json: typing.Any = None,591 params: QueryParamTypes = None,592 headers: HeaderTypes = None,593 cookies: CookieTypes = None,594 stream: bool = False,595 auth: AuthTypes = None,596 allow_redirects: bool = True,597 cert: CertTypes = None,598 verify: VerifyTypes = None,599 timeout: TimeoutTypes = None,600 ) -> Response:Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
lines 601–602why, one step back601 url = self.base_url.join(url)602 cookies = self.merge_cookies(cookies)http3 (#86)Tom Christiebefore adoptionc9747aa
lines 603–606why, one step back603 request = AsyncRequest(604 method,605 url,606 data=self._async_request_data(data),Multipart support (#90)Tom Christiebefore adoption6a44b05
line 607why, one step back607 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 608–610why, one step back608 json=json,609 params=params,610 headers=headers,Support Client(base_url=...)Tom Christiebefore adoption9d5aaff
line 611why, one step back611 cookies=cookies,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 612–740why, one step back612 )613 concurrency_backend = self.concurrency_backend614615 coroutine = self.send616 args = [request]617 kwargs = dict(618 stream=True,619 auth=auth,620 allow_redirects=allow_redirects,621 verify=verify,622 cert=cert,623 timeout=timeout,624 )625 async_response = concurrency_backend.run(coroutine, *args, **kwargs)626627 content = getattr(628 async_response, "_raw_content", getattr(async_response, "_raw_stream", None)629 )630631 sync_content = self._sync_data(content)632633 def sync_on_close() -> None:634 nonlocal concurrency_backend, async_response635 concurrency_backend.run(async_response.on_close)636637 response = Response(638 status_code=async_response.status_code,639 protocol=async_response.protocol,640 headers=async_response.headers,641 content=sync_content,642 on_close=sync_on_close,643 request=async_response.request,644 history=async_response.history,645 )646 if not stream:647 try:648 response.read()649 finally:650 response.close()651 return response652653 def get(654 self,655 url: URLTypes,656 *,657 params: QueryParamTypes = None,658 headers: HeaderTypes = None,659 cookies: CookieTypes = None,660 stream: bool = False,661 auth: AuthTypes = None,662 allow_redirects: bool = True,663 cert: CertTypes = None,664 verify: VerifyTypes = None,665 timeout: TimeoutTypes = None,666 ) -> Response:667 return self.request(668 "GET",669 url,670 params=params,671 headers=headers,672 cookies=cookies,673 stream=stream,674 auth=auth,675 allow_redirects=allow_redirects,676 verify=verify,677 cert=cert,678 timeout=timeout,679 )680681 def options(682 self,683 url: URLTypes,684 *,685 params: QueryParamTypes = None,686 headers: HeaderTypes = None,687 cookies: CookieTypes = None,688 stream: bool = False,689 auth: AuthTypes = None,690 allow_redirects: bool = True,691 cert: CertTypes = None,692 verify: VerifyTypes = None,693 timeout: TimeoutTypes = None,694 ) -> Response:695 return self.request(696 "OPTIONS",697 url,698 params=params,699 headers=headers,700 cookies=cookies,701 stream=stream,702 auth=auth,703 allow_redirects=allow_redirects,704 verify=verify,705 cert=cert,706 timeout=timeout,707 )708709 def head(710 self,711 url: URLTypes,712 *,713 params: QueryParamTypes = None,714 headers: HeaderTypes = None,715 cookies: CookieTypes = None,716 stream: bool = False,717 auth: AuthTypes = None,718 allow_redirects: bool = False, # Note: Differs to usual default.719 cert: CertTypes = None,720 verify: VerifyTypes = None,721 timeout: TimeoutTypes = None,722 ) -> Response:723 return self.request(724 "HEAD",725 url,726 params=params,727 headers=headers,728 cookies=cookies,729 stream=stream,730 auth=auth,731 allow_redirects=allow_redirects,732 verify=verify,733 cert=cert,734 timeout=timeout,735 )736737 def post(738 self,739 url: URLTypes,740 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 741–742why, one step back741 data: RequestData = None,742 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 743–757why, one step back743 json: typing.Any = None,744 params: QueryParamTypes = None,745 headers: HeaderTypes = None,746 cookies: CookieTypes = None,747 stream: bool = False,748 auth: AuthTypes = None,749 allow_redirects: bool = True,750 cert: CertTypes = None,751 verify: VerifyTypes = None,752 timeout: TimeoutTypes = None,753 ) -> Response:754 return self.request(755 "POST",756 url,757 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 758why, one step back758 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 759–774why, one step back759 json=json,760 params=params,761 headers=headers,762 cookies=cookies,763 stream=stream,764 auth=auth,765 allow_redirects=allow_redirects,766 verify=verify,767 cert=cert,768 timeout=timeout,769 )770771 def put(772 self,773 url: URLTypes,774 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 775–776why, one step back775 data: RequestData = None,776 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 777–791why, one step back777 json: typing.Any = None,778 params: QueryParamTypes = None,779 headers: HeaderTypes = None,780 cookies: CookieTypes = None,781 stream: bool = False,782 auth: AuthTypes = None,783 allow_redirects: bool = True,784 cert: CertTypes = None,785 verify: VerifyTypes = None,786 timeout: TimeoutTypes = None,787 ) -> Response:788 return self.request(789 "PUT",790 url,791 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 792why, one step back792 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 793–808why, one step back793 json=json,794 params=params,795 headers=headers,796 cookies=cookies,797 stream=stream,798 auth=auth,799 allow_redirects=allow_redirects,800 verify=verify,801 cert=cert,802 timeout=timeout,803 )804805 def patch(806 self,807 url: URLTypes,808 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 809–810why, one step back809 data: RequestData = None,810 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 811–825why, one step back811 json: typing.Any = None,812 params: QueryParamTypes = None,813 headers: HeaderTypes = None,814 cookies: CookieTypes = None,815 stream: bool = False,816 auth: AuthTypes = None,817 allow_redirects: bool = True,818 cert: CertTypes = None,819 verify: VerifyTypes = None,820 timeout: TimeoutTypes = None,821 ) -> Response:822 return self.request(823 "PATCH",824 url,825 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 826why, one step back826 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 827–842why, one step back827 json=json,828 params=params,829 headers=headers,830 cookies=cookies,831 stream=stream,832 auth=auth,833 allow_redirects=allow_redirects,834 verify=verify,835 cert=cert,836 timeout=timeout,837 )838839 def delete(840 self,841 url: URLTypes,842 *,Multipart support (#90)Tom Christiebefore adoption6a44b05
lines 843–844why, one step back843 data: RequestData = None,844 files: RequestFiles = None,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 845–859why, one step back845 json: typing.Any = None,846 params: QueryParamTypes = None,847 headers: HeaderTypes = None,848 cookies: CookieTypes = None,849 stream: bool = False,850 auth: AuthTypes = None,851 allow_redirects: bool = True,852 cert: CertTypes = None,853 verify: VerifyTypes = None,854 timeout: TimeoutTypes = None,855 ) -> Response:856 return self.request(857 "DELETE",858 url,859 data=data,Multipart support (#90)Tom Christiebefore adoption6a44b05
line 860why, one step back860 files=files,http3 (#86)Tom Christiebefore adoptionc9747aa
lines 861–886why, one step back861 json=json,862 params=params,863 headers=headers,864 cookies=cookies,865 stream=stream,866 auth=auth,867 allow_redirects=allow_redirects,868 verify=verify,869 cert=cert,870 timeout=timeout,871 )872873 def close(self) -> None:874 coroutine = self.dispatch.close875 self.concurrency_backend.run(coroutine)876877 def __enter__(self) -> "Client":878 return self879880 def __exit__(881 self,882 exc_type: typing.Type[BaseException] = None,883 exc_value: BaseException = None,884 traceback: TracebackType = None,885 ) -> None:886 self.close()