client.py
This file
Path
httpcore/client.py
682 lines · 19.1 KiB · Python
Last changed by
Auth (#65)Tom Christiebefore adoption5afa7dd
History of this fileTake it
Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 1why, one step back1import asyncioMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 2–4why, one step back2import typing3from types import TracebackType4Auth (#65)Tom Christiebefore adoption5afa7dd
line 5why, one step back5from .auth import HTTPBasicAuthMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 6–15why, one step back6from .config import (7 DEFAULT_MAX_REDIRECTS,8 DEFAULT_POOL_LIMITS,9 DEFAULT_SSL_CONFIG,10 DEFAULT_TIMEOUT_CONFIG,11 PoolLimits,12 SSLConfig,13 TimeoutConfig,14)15from .dispatch.connection_pool import ConnectionPoolMerge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 16why, one step back16from .exceptions import RedirectBodyUnavailable, RedirectLoop, TooManyRedirectsMerge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 17why, one step back17from .interfaces import ConcurrencyBackend, DispatcherMerge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
lines 18–19why, one step back18from .models import (19 URL,Auth (#65)Tom Christiebefore adoption5afa7dd
line 20why, one step back20 AuthTypes,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 21why, one step back21 Headers,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
lines 22–24why, one step back22 HeaderTypes,23 QueryParamTypes,24 Request,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 25why, one step back25 RequestData,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 26why, one step back26 Response,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 27why, one step back27 SyncResponse,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
lines 28–29why, one step back28 URLTypes,29)Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
line 30why, one step back30from .status_codes import codesMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 31–32why, one step back3132Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 33why, one step back33class AsyncClient:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 34–35why, one step back34 def __init__(35 self,Auth (#65)Tom Christiebefore adoption5afa7dd
line 36why, one step back36 auth: AuthTypes = None,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 37–38why, one step back37 ssl: SSLConfig = DEFAULT_SSL_CONFIG,38 timeout: TimeoutConfig = DEFAULT_TIMEOUT_CONFIG,Truckin' onTom Christiebefore adoption6b60d95
line 39why, one step back39 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 40why, one step back40 max_redirects: int = DEFAULT_MAX_REDIRECTS,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 41why, one step back41 dispatch: Dispatcher = None,Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 42why, one step back42 backend: ConcurrencyBackend = None,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 43why, one step back43 ):Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 44why, one step back44 if dispatch is None:Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 45–47why, one step back45 dispatch = ConnectionPool(46 ssl=ssl, timeout=timeout, pool_limits=pool_limits, backend=backend47 )Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 48why, one step back48Auth (#65)Tom Christiebefore adoption5afa7dd
line 49why, one step back49 self.auth = authMerge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 50–51why, one step back50 self.max_redirects = max_redirects51 self.dispatch = dispatchMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 52–54why, one step back5253 async def get(54 self,Finessing interfaceTom Christiebefore adoptiond7619a9
line 55why, one step back55 url: URLTypes,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 56why, one step back56 *,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 57why, one step back57 query_params: QueryParamTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
line 58why, one step back58 headers: HeaderTypes = None,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 59why, one step back59 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 60why, one step back60 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 61–63why, one step back61 allow_redirects: bool = True,62 ssl: SSLConfig = None,63 timeout: TimeoutConfig = None,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 64–65why, one step back64 ) -> Response:65 return await self.request(Finessing interfaceTom Christiebefore adoptiond7619a9
lines 66–67why, one step back66 "GET",67 url,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 68why, one step back68 query_params=query_params,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 69–70why, one step back69 headers=headers,70 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 71why, one step back71 auth=auth,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 72–74why, one step back72 allow_redirects=allow_redirects,73 ssl=ssl,74 timeout=timeout,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 75–76why, one step back75 )76Finessing interfaceTom Christiebefore adoptiond7619a9
lines 77–80why, one step back77 async def options(78 self,79 url: URLTypes,80 *,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 81why, one step back81 query_params: QueryParamTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 82–83why, one step back82 headers: HeaderTypes = None,83 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 84why, one step back84 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 85–91why, one step back85 allow_redirects: bool = True,86 ssl: SSLConfig = None,87 timeout: TimeoutConfig = None,88 ) -> Response:89 return await self.request(90 "OPTIONS",91 url,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 92why, one step back92 query_params=query_params,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 93–94why, one step back93 headers=headers,94 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 95why, one step back95 auth=auth,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 96–104why, one step back96 allow_redirects=allow_redirects,97 ssl=ssl,98 timeout=timeout,99 )100101 async def head(102 self,103 url: URLTypes,104 *,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 105why, one step back105 query_params: QueryParamTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 106–107why, one step back106 headers: HeaderTypes = None,107 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 108why, one step back108 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 109–115why, one step back109 allow_redirects: bool = False, # Note: Differs to usual default.110 ssl: SSLConfig = None,111 timeout: TimeoutConfig = None,112 ) -> Response:113 return await self.request(114 "HEAD",115 url,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 116why, one step back116 query_params=query_params,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 117–118why, one step back117 headers=headers,118 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 119why, one step back119 auth=auth,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 120–124why, one step back120 allow_redirects=allow_redirects,121 ssl=ssl,122 timeout=timeout,123 )124Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 125–126why, one step back125 async def post(126 self,Finessing interfaceTom Christiebefore adoptiond7619a9
line 127why, one step back127 url: URLTypes,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 128why, one step back128 *,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 129why, one step back129 data: RequestData = b"",Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 130why, one step back130 query_params: QueryParamTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
line 131why, one step back131 headers: HeaderTypes = None,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 132why, one step back132 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 133why, one step back133 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 134–136why, one step back134 allow_redirects: bool = True,135 ssl: SSLConfig = None,136 timeout: TimeoutConfig = None,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 137–140why, one step back137 ) -> Response:138 return await self.request(139 "POST",140 url,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 141why, one step back141 data=data,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 142why, one step back142 query_params=query_params,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 143–144why, one step back143 headers=headers,144 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 145why, one step back145 auth=auth,Finessing interfaceTom Christiebefore adoptiond7619a9
line 146why, one step back146 allow_redirects=allow_redirects,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 147–150why, one step back147 ssl=ssl,148 timeout=timeout,149 )150Finessing interfaceTom Christiebefore adoptiond7619a9
lines 151–154why, one step back151 async def put(152 self,153 url: URLTypes,154 *,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 155why, one step back155 data: RequestData = b"",Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 156why, one step back156 query_params: QueryParamTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 157–158why, one step back157 headers: HeaderTypes = None,158 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 159why, one step back159 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 160–166why, one step back160 allow_redirects: bool = True,161 ssl: SSLConfig = None,162 timeout: TimeoutConfig = None,163 ) -> Response:164 return await self.request(165 "PUT",166 url,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 167why, one step back167 data=data,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 168why, one step back168 query_params=query_params,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 169–170why, one step back169 headers=headers,170 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 171why, one step back171 auth=auth,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 172–180why, one step back172 allow_redirects=allow_redirects,173 ssl=ssl,174 timeout=timeout,175 )176177 async def patch(178 self,179 url: URLTypes,180 *,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 181why, one step back181 data: RequestData = b"",Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 182why, one step back182 query_params: QueryParamTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 183–184why, one step back183 headers: HeaderTypes = None,184 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 185why, one step back185 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 186–192why, one step back186 allow_redirects: bool = True,187 ssl: SSLConfig = None,188 timeout: TimeoutConfig = None,189 ) -> Response:190 return await self.request(191 "PATCH",192 url,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 193why, one step back193 data=data,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 194why, one step back194 query_params=query_params,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 195–196why, one step back195 headers=headers,196 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 197why, one step back197 auth=auth,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 198–206why, one step back198 allow_redirects=allow_redirects,199 ssl=ssl,200 timeout=timeout,201 )202203 async def delete(204 self,205 url: URLTypes,206 *,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 207why, one step back207 data: RequestData = b"",Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 208why, one step back208 query_params: QueryParamTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 209–210why, one step back209 headers: HeaderTypes = None,210 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 211why, one step back211 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 212–218why, one step back212 allow_redirects: bool = True,213 ssl: SSLConfig = None,214 timeout: TimeoutConfig = None,215 ) -> Response:216 return await self.request(217 "DELETE",218 url,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 219why, one step back219 data=data,Merge pull request #42 from encode/query-paramsTom Christiebefore adoption3de0425
line 220why, one step back220 query_params=query_params,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 221–222why, one step back221 headers=headers,222 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 223why, one step back223 auth=auth,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 224–228why, one step back224 allow_redirects=allow_redirects,225 ssl=ssl,226 timeout=timeout,227 )228Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 229–237why, one step back229 async def request(230 self,231 method: str,232 url: URLTypes,233 *,234 data: RequestData = b"",235 query_params: QueryParamTypes = None,236 headers: HeaderTypes = None,237 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 238why, one step back238 auth: AuthTypes = None,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 239–249why, one step back239 allow_redirects: bool = True,240 ssl: SSLConfig = None,241 timeout: TimeoutConfig = None,242 ) -> Response:243 request = Request(244 method, url, data=data, query_params=query_params, headers=headers245 )246 self.prepare_request(request)247 response = await self.send(248 request,249 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 250why, one step back250 auth=auth,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 251–256why, one step back251 allow_redirects=allow_redirects,252 ssl=ssl,253 timeout=timeout,254 )255 return response256Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 257why, one step back257 def prepare_request(self, request: Request) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 258why, one step back258 request.prepare()Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 259–264why, one step back259260 async def send(261 self,262 request: Request,263 *,264 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 265why, one step back265 auth: AuthTypes = None,Finessing interfaceTom Christiebefore adoptiond7619a9
lines 266–267why, one step back266 ssl: SSLConfig = None,267 timeout: TimeoutConfig = None,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 268why, one step back268 allow_redirects: bool = True,Auth (#65)Tom Christiebefore adoption5afa7dd
lines 269–298why, one step back269 ) -> Response:270 if auth is None:271 auth = self.auth272273 url = request.url274 if auth is None and (url.username or url.password):275 auth = HTTPBasicAuth(username=url.username, password=url.password)276277 if auth is not None:278 if isinstance(auth, tuple):279 auth = HTTPBasicAuth(username=auth[0], password=auth[1])280 request = auth(request)281282 response = await self.send_handling_redirects(283 request,284 stream=stream,285 ssl=ssl,286 timeout=timeout,287 allow_redirects=allow_redirects,288 )289 return response290291 async def send_handling_redirects(292 self,293 request: Request,294 *,295 stream: bool = False,296 ssl: SSLConfig = None,297 timeout: TimeoutConfig = None,298 allow_redirects: bool = True,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 299why, one step back299 history: typing.List[Response] = None,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 300why, one step back300 ) -> Response:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 301–302why, one step back301 if history is None:302 history = []Finessing interfaceTom Christiebefore adoptiond7619a9
line 303why, one step back303Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 304–310why, one step back304 while True:305 # We perform these checks here, so that calls to `response.next()`306 # will raise redirect errors if appropriate.307 if len(history) > self.max_redirects:308 raise TooManyRedirects()309 if request.url in [response.url for response in history]:310 raise RedirectLoop()Finessing interfaceTom Christiebefore adoptiond7619a9
line 311why, one step back311Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 312–318why, one step back312 response = await self.dispatch.send(313 request, stream=stream, ssl=ssl, timeout=timeout314 )315 response.history = list(history)316 history = [response] + history317 if not response.is_redirect:318 breakMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 319why, one step back319Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 320–326why, one step back320 if allow_redirects:321 request = self.build_redirect_request(request, response)322 else:323324 async def send_next() -> Response:325 nonlocal request, response, ssl, allow_redirects, timeout, history326 request = self.build_redirect_request(request, response)Auth (#65)Tom Christiebefore adoption5afa7dd
line 327why, one step back327 response = await self.send_handling_redirects(Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 328–356why, one step back328 request,329 stream=stream,330 allow_redirects=allow_redirects,331 ssl=ssl,332 timeout=timeout,333 history=history,334 )335 return response336337 response.next = send_next # type: ignore338 break339340 return response341342 def build_redirect_request(self, request: Request, response: Response) -> Request:343 method = self.redirect_method(request, response)344 url = self.redirect_url(request, response)345 headers = self.redirect_headers(request, url)346 content = self.redirect_content(request, method)347 return Request(method=method, url=url, headers=headers, data=content)348349 def redirect_method(self, request: Request, response: Response) -> str:350 """351 When being redirected we may want to change the method of the request352 based on certain specs or browser behavior.353 """354 method = request.method355356 # https://tools.ietf.org/html/rfc7231#section-6.4.4Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
line 357why, one step back357 if response.status_code == codes.SEE_OTHER and method != "HEAD":Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 358–361why, one step back358 method = "GET"359360 # Do what the browsers do, despite standards...361 # Turn 302s into GETs.Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
line 362why, one step back362 if response.status_code == codes.FOUND and method != "HEAD":Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 363–366why, one step back363 method = "GET"364365 # If a POST is responded to with a 301, turn it into a GET.366 # This bizarre behaviour is explained in 'requests' issue 1704.Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
line 367why, one step back367 if response.status_code == codes.MOVED_PERMANENTLY and method == "POST":Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 368–410why, one step back368 method = "GET"369370 return method371372 def redirect_url(self, request: Request, response: Response) -> URL:373 """374 Return the URL for the redirect to follow.375 """376 location = response.headers["Location"]377378 url = URL(location, allow_relative=True)379380 # Facilitate relative 'Location' headers, as allowed by RFC 7231.381 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')382 if url.is_relative_url:383 url = url.resolve_with(request.url)384385 # Attach previous fragment if needed (RFC 7231 7.1.2)386 if request.url.fragment and not url.fragment:387 url = url.copy_with(fragment=request.url.fragment)388389 return url390391 def redirect_headers(self, request: Request, url: URL) -> Headers:392 """393 Strip Authorization headers when responses are redirected away from394 the origin.395 """396 headers = Headers(request.headers)397 if url.origin != request.url.origin:398 del headers["Authorization"]399 return headers400401 def redirect_content(self, request: Request, method: str) -> bytes:402 """403 Return the body that should be used for the redirect request.404 """405 if method != request.method and method == "GET":406 return b""407 if request.is_streaming:408 raise RedirectBodyUnavailable()409 return request.content410Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 411why, one step back411 async def close(self) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 412why, one step back412 await self.dispatch.close()Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 413why, one step back413Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
line 414why, one step back414 async def __aenter__(self) -> "AsyncClient":Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 415–423why, one step back415 return self416417 async def __aexit__(418 self,419 exc_type: typing.Type[BaseException] = None,420 exc_value: BaseException = None,421 traceback: TracebackType = None,422 ) -> None:423 await self.close()Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 424–428why, one step back424425426class Client:427 def __init__(428 self,Auth (#65)Tom Christiebefore adoption5afa7dd
line 429why, one step back429 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 430–434why, one step back430 ssl: SSLConfig = DEFAULT_SSL_CONFIG,431 timeout: TimeoutConfig = DEFAULT_TIMEOUT_CONFIG,432 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,433 max_redirects: int = DEFAULT_MAX_REDIRECTS,434 dispatch: Dispatcher = None,Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 435why, one step back435 backend: ConcurrencyBackend = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 436–437why, one step back436 ) -> None:437 self._client = AsyncClient(Auth (#65)Tom Christiebefore adoption5afa7dd
line 438why, one step back438 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 439–443why, one step back439 ssl=ssl,440 timeout=timeout,441 pool_limits=pool_limits,442 max_redirects=max_redirects,443 dispatch=dispatch,Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 444why, one step back444 backend=backend,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 445–456why, one step back445 )446 self._loop = asyncio.new_event_loop()447448 def request(449 self,450 method: str,451 url: URLTypes,452 *,453 data: RequestData = b"",454 query_params: QueryParamTypes = None,455 headers: HeaderTypes = None,456 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 457why, one step back457 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 458–468why, one step back458 allow_redirects: bool = True,459 ssl: SSLConfig = None,460 timeout: TimeoutConfig = None,461 ) -> SyncResponse:462 request = Request(463 method, url, data=data, query_params=query_params, headers=headers464 )465 self.prepare_request(request)466 response = self.send(467 request,468 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 469why, one step back469 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 470–482why, one step back470 allow_redirects=allow_redirects,471 ssl=ssl,472 timeout=timeout,473 )474 return response475476 def get(477 self,478 url: URLTypes,479 *,480 query_params: QueryParamTypes = None,481 headers: HeaderTypes = None,482 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 483why, one step back483 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 484–492why, one step back484 allow_redirects: bool = True,485 ssl: SSLConfig = None,486 timeout: TimeoutConfig = None,487 ) -> SyncResponse:488 return self.request(489 "GET",490 url,491 headers=headers,492 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 493why, one step back493 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 494–505why, one step back494 allow_redirects=allow_redirects,495 ssl=ssl,496 timeout=timeout,497 )498499 def options(500 self,501 url: URLTypes,502 *,503 query_params: QueryParamTypes = None,504 headers: HeaderTypes = None,505 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 506why, one step back506 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 507–515why, one step back507 allow_redirects: bool = True,508 ssl: SSLConfig = None,509 timeout: TimeoutConfig = None,510 ) -> SyncResponse:511 return self.request(512 "OPTIONS",513 url,514 headers=headers,515 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 516why, one step back516 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 517–528why, one step back517 allow_redirects=allow_redirects,518 ssl=ssl,519 timeout=timeout,520 )521522 def head(523 self,524 url: URLTypes,525 *,526 query_params: QueryParamTypes = None,527 headers: HeaderTypes = None,528 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 529why, one step back529 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 530–538why, one step back530 allow_redirects: bool = False, # Note: Differs to usual default.531 ssl: SSLConfig = None,532 timeout: TimeoutConfig = None,533 ) -> SyncResponse:534 return self.request(535 "HEAD",536 url,537 headers=headers,538 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 539why, one step back539 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 540–552why, one step back540 allow_redirects=allow_redirects,541 ssl=ssl,542 timeout=timeout,543 )544545 def post(546 self,547 url: URLTypes,548 *,549 data: RequestData = b"",550 query_params: QueryParamTypes = None,551 headers: HeaderTypes = None,552 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 553why, one step back553 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 554–563why, one step back554 allow_redirects: bool = True,555 ssl: SSLConfig = None,556 timeout: TimeoutConfig = None,557 ) -> SyncResponse:558 return self.request(559 "POST",560 url,561 data=data,562 headers=headers,563 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 564why, one step back564 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 565–577why, one step back565 allow_redirects=allow_redirects,566 ssl=ssl,567 timeout=timeout,568 )569570 def put(571 self,572 url: URLTypes,573 *,574 data: RequestData = b"",575 query_params: QueryParamTypes = None,576 headers: HeaderTypes = None,577 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 578why, one step back578 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 579–588why, one step back579 allow_redirects: bool = True,580 ssl: SSLConfig = None,581 timeout: TimeoutConfig = None,582 ) -> SyncResponse:583 return self.request(584 "PUT",585 url,586 data=data,587 headers=headers,588 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 589why, one step back589 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 590–602why, one step back590 allow_redirects=allow_redirects,591 ssl=ssl,592 timeout=timeout,593 )594595 def patch(596 self,597 url: URLTypes,598 *,599 data: RequestData = b"",600 query_params: QueryParamTypes = None,601 headers: HeaderTypes = None,602 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 603why, one step back603 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 604–613why, one step back604 allow_redirects: bool = True,605 ssl: SSLConfig = None,606 timeout: TimeoutConfig = None,607 ) -> SyncResponse:608 return self.request(609 "PATCH",610 url,611 data=data,612 headers=headers,613 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 614why, one step back614 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 615–627why, one step back615 allow_redirects=allow_redirects,616 ssl=ssl,617 timeout=timeout,618 )619620 def delete(621 self,622 url: URLTypes,623 *,624 data: RequestData = b"",625 query_params: QueryParamTypes = None,626 headers: HeaderTypes = None,627 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 628why, one step back628 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 629–638why, one step back629 allow_redirects: bool = True,630 ssl: SSLConfig = None,631 timeout: TimeoutConfig = None,632 ) -> SyncResponse:633 return self.request(634 "DELETE",635 url,636 data=data,637 headers=headers,638 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 639why, one step back639 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 640–652why, one step back640 allow_redirects=allow_redirects,641 ssl=ssl,642 timeout=timeout,643 )644645 def prepare_request(self, request: Request) -> None:646 self._client.prepare_request(request)647648 def send(649 self,650 request: Request,651 *,652 stream: bool = False,Auth (#65)Tom Christiebefore adoption5afa7dd
line 653why, one step back653 auth: AuthTypes = None,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 654–661why, one step back654 allow_redirects: bool = True,655 ssl: SSLConfig = None,656 timeout: TimeoutConfig = None,657 ) -> SyncResponse:658 response = self._loop.run_until_complete(659 self._client.send(660 request,661 stream=stream,Auth (#65)Tom Christiebefore adoption5afa7dd
line 662why, one step back662 auth=auth,Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0
lines 663–682why, one step back663 allow_redirects=allow_redirects,664 ssl=ssl,665 timeout=timeout,666 )667 )668 return SyncResponse(response, self._loop)669670 def close(self) -> None:671 self._loop.run_until_complete(self._client.close())672673 def __enter__(self) -> "Client":674 return self675676 def __exit__(677 self,678 exc_type: typing.Type[BaseException] = None,679 exc_value: BaseException = None,680 traceback: TracebackType = None,681 ) -> None:682 self.close()