interfaces.py
This file
Path
httpcore/interfaces.py
119 lines · 3.1 KiB · Python
Last changed by
Minor docstring tweakTom Christiebefore adoptionf1b10e5
History of this fileTake it
Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
line 1why, one step back1import enumMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 2–4why, one step back2import typing3from types import TracebackType4Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 5why, one step back5from .config import SSLConfig, TimeoutConfigMerge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 6–7why, one step back6from .models import (7 URL,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 8why, one step back8 Headers,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 9–15why, one step back9 HeaderTypes,10 QueryParamTypes,11 Request,12 RequestData,13 Response,14 URLTypes,15)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 16–17why, one step back1617OptionalTimeout = typing.Optional[TimeoutConfig]Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
lines 18–22why, one step back181920class Protocol(str, enum.Enum):21 HTTP_11 = "HTTP/1.1"22 HTTP_2 = "HTTP/2"Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 23–24why, one step back2324Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 25why, one step back25class Dispatcher:Updating docstringsTom Christiebefore adoption5f8000f
line 26why, one step back26 """Minor docstring tweakTom Christiebefore adoptionf1b10e5
line 27why, one step back27 Base class for dispatcher classes, that handle sending the request.Updating docstringsTom Christiebefore adoption5f8000f
lines 28–29why, one step back2829 Stubs out the interface, as well as providing a `.request()` convienenceMinor docstring tweakTom Christiebefore adoptionf1b10e5
line 30why, one step back30 implementation, to make it easy to use or test stand-alone dispatchers,Updating docstringsTom Christiebefore adoption5f8000f
lines 31–33why, one step back31 without requiring a complete `Client` instance.32 """33Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 34–36why, one step back34 async def request(35 self,36 method: str,Prefer 'content' over 'body'Tom Christiebefore adoption4255d41
line 37why, one step back37 url: URLTypes,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 38why, one step back38 *,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 39–40why, one step back39 data: RequestData = b"",40 query_params: QueryParamTypes = None,Prefer 'content' over 'body'Tom Christiebefore adoption4255d41
line 41why, one step back41 headers: HeaderTypes = None,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 42–44why, one step back42 stream: bool = False,43 ssl: SSLConfig = None,44 timeout: TimeoutConfig = NoneMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 45why, one step back45 ) -> Response:Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 46–48why, one step back46 request = Request(47 method, url, data=data, query_params=query_params, headers=headers48 )Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 49why, one step back49 self.prepare_request(request)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 50why, one step back50 response = await self.send(request, stream=stream, ssl=ssl, timeout=timeout)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 51–53why, one step back51 return response5253 def prepare_request(self, request: Request) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 54why, one step back54 request.prepare()Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 55why, one step back55Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 56–62why, one step back56 async def send(57 self,58 request: Request,59 stream: bool = False,60 ssl: SSLConfig = None,61 timeout: TimeoutConfig = None,62 ) -> Response:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 63–65why, one step back63 raise NotImplementedError() # pragma: nocover6465 async def close(self) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 66why, one step back66 pass # pragma: nocoverMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 67why, one step back67Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 68why, one step back68 async def __aenter__(self) -> "Dispatcher":Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 69–80why, one step back69 return self7071 async def __aexit__(72 self,73 exc_type: typing.Type[BaseException] = None,74 exc_value: BaseException = None,75 traceback: TracebackType = None,76 ) -> None:77 await self.close()787980class BaseReader:Updating docstringsTom Christiebefore adoption5f8000f
lines 81–86why, one step back81 """82 A stream reader. Abstracts away any asyncio-specfic interfaces83 into a more generic base class, that we can use with alternate84 backend, or for stand-alone test cases.85 """86Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 87–91why, one step back87 async def read(self, n: int, timeout: OptionalTimeout = None) -> bytes:88 raise NotImplementedError() # pragma: no cover899091class BaseWriter:Updating docstringsTom Christiebefore adoption5f8000f
lines 92–97why, one step back92 """93 A stream writer. Abstracts away any asyncio-specfic interfaces94 into a more generic base class, that we can use with alternate95 backend, or for stand-alone test cases.96 """97Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 98–108why, one step back98 def write_no_block(self, data: bytes) -> None:99 raise NotImplementedError() # pragma: no cover100101 async def write(self, data: bytes, timeout: OptionalTimeout = None) -> None:102 raise NotImplementedError() # pragma: no cover103104 async def close(self) -> None:105 raise NotImplementedError() # pragma: no cover106107108class BasePoolSemaphore:Updating docstringsTom Christiebefore adoption5f8000f
lines 109–114why, one step back109 """110 A semaphore for use with connection pooling.111112 Abstracts away any asyncio-specfic interfaces.113 """114Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 115–119why, one step back115 async def acquire(self) -> None:116 raise NotImplementedError() # pragma: no cover117118 def release(self) -> None:119 raise NotImplementedError() # pragma: no cover