interfaces.py
This file
Path
httpcore/interfaces.py
134 lines · 3.5 KiB · Python
Last changed by
Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
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 #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 2why, one step back2import sslMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 3–5why, one step back3import typing4from types import TracebackType5Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
line 6why, one step back6from .config import PoolLimits, SSLConfig, TimeoutConfigMerge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 7–8why, one step back7from .models import (8 URL,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 9why, one step back9 Headers,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 10–16why, one step back10 HeaderTypes,11 QueryParamTypes,12 Request,13 RequestData,14 Response,15 URLTypes,16)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 17–18why, one step back1718OptionalTimeout = typing.Optional[TimeoutConfig]Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
lines 19–23why, one step back192021class Protocol(str, enum.Enum):22 HTTP_11 = "HTTP/1.1"23 HTTP_2 = "HTTP/2"Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 24–25why, one step back2425Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 26why, one step back26class Dispatcher:Updating docstringsTom Christiebefore adoption5f8000f
line 27why, one step back27 """Minor docstring tweakTom Christiebefore adoptionf1b10e5
line 28why, one step back28 Base class for dispatcher classes, that handle sending the request.Updating docstringsTom Christiebefore adoption5f8000f
lines 29–30why, one step back2930 Stubs out the interface, as well as providing a `.request()` convienenceMinor docstring tweakTom Christiebefore adoptionf1b10e5
line 31why, one step back31 implementation, to make it easy to use or test stand-alone dispatchers,Updating docstringsTom Christiebefore adoption5f8000f
lines 32–34why, one step back32 without requiring a complete `Client` instance.33 """34Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 35–37why, one step back35 async def request(36 self,37 method: str,Prefer 'content' over 'body'Tom Christiebefore adoption4255d41
line 38why, one step back38 url: URLTypes,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 39why, one step back39 *,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 40–41why, one step back40 data: RequestData = b"",41 query_params: QueryParamTypes = None,Prefer 'content' over 'body'Tom Christiebefore adoption4255d41
line 42why, one step back42 headers: HeaderTypes = None,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 43–45why, one step back43 stream: bool = False,44 ssl: SSLConfig = None,45 timeout: TimeoutConfig = NoneMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 46why, one step back46 ) -> Response:Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
lines 47–49why, one step back47 request = Request(48 method, url, data=data, query_params=query_params, headers=headers49 )Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 50why, one step back50 self.prepare_request(request)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 51why, one step back51 response = await self.send(request, stream=stream, ssl=ssl, timeout=timeout)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 52–54why, one step back52 return response5354 def prepare_request(self, request: Request) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 55why, one step back55 request.prepare()Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 56why, one step back56Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 57–63why, one step back57 async def send(58 self,59 request: Request,60 stream: bool = False,61 ssl: SSLConfig = None,62 timeout: TimeoutConfig = None,63 ) -> Response:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 64–66why, one step back64 raise NotImplementedError() # pragma: nocover6566 async def close(self) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 67why, one step back67 pass # pragma: nocoverMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 68why, one step back68Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 69why, one step back69 async def __aenter__(self) -> "Dispatcher":Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 70–81why, one step back70 return self7172 async def __aexit__(73 self,74 exc_type: typing.Type[BaseException] = None,75 exc_value: BaseException = None,76 traceback: TracebackType = None,77 ) -> None:78 await self.close()798081class BaseReader:Updating docstringsTom Christiebefore adoption5f8000f
lines 82–87why, one step back82 """83 A stream reader. Abstracts away any asyncio-specfic interfaces84 into a more generic base class, that we can use with alternate85 backend, or for stand-alone test cases.86 """87Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 88–92why, one step back88 async def read(self, n: int, timeout: OptionalTimeout = None) -> bytes:89 raise NotImplementedError() # pragma: no cover909192class BaseWriter:Updating docstringsTom Christiebefore adoption5f8000f
lines 93–98why, one step back93 """94 A stream writer. Abstracts away any asyncio-specfic interfaces95 into a more generic base class, that we can use with alternate96 backend, or for stand-alone test cases.97 """98Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 99–109why, one step back99 def write_no_block(self, data: bytes) -> None:100 raise NotImplementedError() # pragma: no cover101102 async def write(self, data: bytes, timeout: OptionalTimeout = None) -> None:103 raise NotImplementedError() # pragma: no cover104105 async def close(self) -> None:106 raise NotImplementedError() # pragma: no cover107108109class BasePoolSemaphore:Updating docstringsTom Christiebefore adoption5f8000f
lines 110–115why, one step back110 """111 A semaphore for use with connection pooling.112113 Abstracts away any asyncio-specfic interfaces.114 """115Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 116–119why, one step back116 async def acquire(self) -> None:117 raise NotImplementedError() # pragma: no cover118119 def release(self) -> None:Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 120–133why, one step back120 raise NotImplementedError() # pragma: no cover121122123class ConcurrencyBackend:124 async def connect(125 self,126 hostname: str,127 port: int,128 ssl_context: typing.Optional[ssl.SSLContext],129 timeout: TimeoutConfig,130 ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:131 raise NotImplementedError() # pragma: no cover132133 def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 134why, one step back134 raise NotImplementedError() # pragma: no cover