interfaces.py
This file
Path
httpcore/interfaces.py
132 lines · 3.5 KiB · Python
Last changed by
query_params -> paramsTom Christiebefore adoptionbb70377
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
line 40why, one step back40 data: RequestData = b"",query_params -> paramsTom Christiebefore adoptionbb70377
line 41why, one step back41 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:query_params -> paramsTom Christiebefore adoptionbb70377
line 47why, one step back47 request = Request(method, url, data=data, params=params, headers=headers)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 48why, one step back48 self.prepare_request(request)Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 49why, one step back49 response = await self.send(request, stream=stream, ssl=ssl, timeout=timeout)Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 50–52why, one step back50 return response5152 def prepare_request(self, request: Request) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 53why, one step back53 request.prepare()Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 54why, one step back54Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
lines 55–61why, one step back55 async def send(56 self,57 request: Request,58 stream: bool = False,59 ssl: SSLConfig = None,60 timeout: TimeoutConfig = None,61 ) -> Response:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 62–64why, one step back62 raise NotImplementedError() # pragma: nocover6364 async def close(self) -> None:Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 65why, one step back65 pass # pragma: nocoverMerge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 66why, one step back66Merge pull request #55 from encode/drop-adaptersTom Christiebefore adoptiond72a144
line 67why, one step back67 async def __aenter__(self) -> "Dispatcher":Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 68–79why, one step back68 return self6970 async def __aexit__(71 self,72 exc_type: typing.Type[BaseException] = None,73 exc_value: BaseException = None,74 traceback: TracebackType = None,75 ) -> None:76 await self.close()777879class BaseReader:Updating docstringsTom Christiebefore adoption5f8000f
lines 80–85why, one step back80 """81 A stream reader. Abstracts away any asyncio-specfic interfaces82 into a more generic base class, that we can use with alternate83 backend, or for stand-alone test cases.84 """85Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 86–90why, one step back86 async def read(self, n: int, timeout: OptionalTimeout = None) -> bytes:87 raise NotImplementedError() # pragma: no cover888990class BaseWriter:Updating docstringsTom Christiebefore adoption5f8000f
lines 91–96why, one step back91 """92 A stream writer. Abstracts away any asyncio-specfic interfaces93 into a more generic base class, that we can use with alternate94 backend, or for stand-alone test cases.95 """96Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 97–107why, one step back97 def write_no_block(self, data: bytes) -> None:98 raise NotImplementedError() # pragma: no cover99100 async def write(self, data: bytes, timeout: OptionalTimeout = None) -> None:101 raise NotImplementedError() # pragma: no cover102103 async def close(self) -> None:104 raise NotImplementedError() # pragma: no cover105106107class BasePoolSemaphore:Updating docstringsTom Christiebefore adoption5f8000f
lines 108–113why, one step back108 """109 A semaphore for use with connection pooling.110111 Abstracts away any asyncio-specfic interfaces.112 """113Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
lines 114–117why, one step back114 async def acquire(self) -> None:115 raise NotImplementedError() # pragma: no cover116117 def release(self) -> None:Merge pull request #60 from encode/concurrency-backend-classTom Christiebefore adoption3d997af
lines 118–131why, one step back118 raise NotImplementedError() # pragma: no cover119120121class ConcurrencyBackend:122 async def connect(123 self,124 hostname: str,125 port: int,126 ssl_context: typing.Optional[ssl.SSLContext],127 timeout: TimeoutConfig,128 ) -> typing.Tuple[BaseReader, BaseWriter, Protocol]:129 raise NotImplementedError() # pragma: no cover130131 def get_semaphore(self, limits: PoolLimits) -> BasePoolSemaphore:Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054
line 132why, one step back132 raise NotImplementedError() # pragma: no cover