interfaces.py
This file
Path
httpcore/interfaces.py
130 lines · 3.5 KiB · Python
Last changed by
Drop prepare_requestTom Christiebefore adoption37da9ed
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 TracebackType5Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
line 6why, one step back6from .config import CertTypes, PoolLimits, TimeoutConfig, TimeoutTypes, VerifyTypesMerge 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
line 17why, one step back17Merge pull request #59 from encode/use-stdlib-status-codesTom Christiebefore adoptionafc8369
lines 18–21why, one step back1819class Protocol(str, enum.Enum):20 HTTP_11 = "HTTP/1.1"21 HTTP_2 = "HTTP/2"Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 22–23why, one step back2223Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 24why, one step back24class Dispatcher:Updating docstringsTom Christiebefore adoption5f8000f
line 25why, one step back25 """Minor docstring tweakTom Christiebefore adoptionf1b10e5
line 26why, one step back26 Base class for dispatcher classes, that handle sending the request.Updating docstringsTom Christiebefore adoption5f8000f
lines 27–28why, one step back2728 Stubs out the interface, as well as providing a `.request()` convienenceMinor docstring tweakTom Christiebefore adoptionf1b10e5
line 29why, one step back29 implementation, to make it easy to use or test stand-alone dispatchers,Updating docstringsTom Christiebefore adoption5f8000f
lines 30–32why, one step back30 without requiring a complete `Client` instance.31 """32Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 33–35why, one step back33 async def request(34 self,35 method: str,Prefer 'content' over 'body'Tom Christiebefore adoption4255d41
line 36why, one step back36 url: URLTypes,Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 37why, one step back37 *,Merge pull request #44 from encode/request-dataTom Christiebefore adoption39a5c53
line 38why, one step back38 data: RequestData = b"",query_params -> paramsTom Christiebefore adoptionbb70377
line 39why, one step back39 params: QueryParamTypes = None,Prefer 'content' over 'body'Tom Christiebefore adoption4255d41
line 40why, one step back40 headers: HeaderTypes = None,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 41why, one step back41 stream: bool = False,Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
lines 42–44why, one step back42 verify: VerifyTypes = None,43 cert: CertTypes = None,44 timeout: TimeoutTypes = NoneMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 45why, one step back45 ) -> Response:query_params -> paramsTom Christiebefore adoptionbb70377
line 46why, one step back46 request = Request(method, url, data=data, params=params, headers=headers)Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
lines 47–49why, one step back47 response = await self.send(48 request, stream=stream, verify=verify, cert=cert, timeout=timeout49 )Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 50–51why, one step back50 return response51Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 52–55why, one step back52 async def send(53 self,54 request: Request,55 stream: bool = False,Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
lines 56–58why, one step back56 verify: VerifyTypes = None,57 cert: CertTypes = None,58 timeout: TimeoutTypes = None,Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 59why, one step back59 ) -> Response:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 60–62why, one step back60 raise NotImplementedError() # pragma: nocover6162 async def close(self) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 63why, one step back63 pass # pragma: nocoverMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 64why, one step back64Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 65why, one step back65 async def __aenter__(self) -> "Dispatcher":Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 66–77why, one step back66 return self6768 async def __aexit__(69 self,70 exc_type: typing.Type[BaseException] = None,71 exc_value: BaseException = None,72 traceback: TracebackType = None,73 ) -> None:74 await self.close()757677class BaseReader:Updating docstringsTom Christiebefore adoption5f8000f
lines 78–83why, one step back78 """79 A stream reader. Abstracts away any asyncio-specfic interfaces80 into a more generic base class, that we can use with alternate81 backend, or for stand-alone test cases.82 """83Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
line 84why, one step back84 async def read(self, n: int, timeout: TimeoutConfig = None) -> bytes:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 85–88why, one step back85 raise NotImplementedError() # pragma: no cover868788class BaseWriter:Updating docstringsTom Christiebefore adoption5f8000f
lines 89–94why, one step back89 """90 A stream writer. Abstracts away any asyncio-specfic interfaces91 into a more generic base class, that we can use with alternate92 backend, or for stand-alone test cases.93 """94Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 95–97why, one step back95 def write_no_block(self, data: bytes) -> None:96 raise NotImplementedError() # pragma: no cover97Work on bringing API into parity with `requests`. (#76)Tom Christiebefore adoption9574041
line 98why, one step back98 async def write(self, data: bytes, timeout: TimeoutConfig = None) -> None:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 99–105why, one step back99 raise NotImplementedError() # pragma: no cover100101 async def close(self) -> None:102 raise NotImplementedError() # pragma: no cover103104105class BasePoolSemaphore:Updating docstringsTom Christiebefore adoption5f8000f
lines 106–111why, one step back106 """107 A semaphore for use with connection pooling.108109 Abstracts away any asyncio-specfic interfaces.110 """111Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 112–115why, one step back112 async def acquire(self) -> None:113 raise NotImplementedError() # pragma: no cover114115 def release(self) -> None:Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 116–129why, one step back116 raise NotImplementedError() # pragma: no cover117118119class ConcurrencyBackend:120 async def connect(121 self,122 hostname: str,123 port: int,124 ssl_context: typing.Optional[ssl.SSLContext],125 timeout: TimeoutConfig,126 ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:127 raise NotImplementedError() # pragma: no cover128129 def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 130why, one step back130 raise NotImplementedError() # pragma: no cover