class IdentityDecoder(Decoder):
+ """
+ Handle unencoded data.
+ """
+
def decode(self, data: bytes) -> bytes:
return data
"""
Handle 'brotli' decoding.
- Requires `pip install brotlipy`.
- See: https://brotlipy.readthedocs.io/
+ Requires `pip install brotlipy`. See: https://brotlipy.readthedocs.io/
"""
def __init__(self) -> None:
def __init__(self, children: typing.Sequence[Decoder]) -> None:
"""
- children should be a sequence of decoders in the order in which
+ 'children' should be a sequence of decoders in the order in which
each was applied.
"""
# Note that we reverse the order for decoding.
"""
+class DecodingError(Exception):
+ """
+ Decoding of the response failed.
+ """
+
+
# Redirect exceptions...
"""
-# Response exceptions...
+# Stream exceptions...
+
+class StreamException(Exception):
+ """
+ The base class for stream exceptions.
-class StreamConsumed(Exception):
+ The developer made an error in accessing the request stream in
+ an invalid way.
+ """
+
+
+class StreamConsumed(StreamException):
"""
Attempted to read or stream response content, but the content has already
been streamed.
"""
-class ResponseNotRead(Exception):
+class ResponseNotRead(StreamException):
"""
Attempted to access response content, without having called `read()`
after a streaming response.
"""
-class ResponseClosed(Exception):
+class ResponseClosed(StreamException):
"""
Attempted to read or stream response content, but the request has been
- closed without loading the body.
- """
-
-
-class DecodingError(Exception):
- """
- Decoding of the response failed.
+ closed.
"""
class Adapter:
+ """
+ The base class for all adapter or dispatcher classes.
+
+ Stubs out the interface, as well as providing a `.request()` convienence
+ implementation, to make it easy to use or test stand-alone adapters,
+ without requiring a complete `Client` instance.
+ """
+
async def request(
self,
method: str,
class BaseReader:
+ """
+ A stream reader. Abstracts away any asyncio-specfic interfaces
+ into a more generic base class, that we can use with alternate
+ backend, or for stand-alone test cases.
+ """
+
async def read(self, n: int, timeout: OptionalTimeout = None) -> bytes:
raise NotImplementedError() # pragma: no cover
class BaseWriter:
+ """
+ A stream writer. Abstracts away any asyncio-specfic interfaces
+ into a more generic base class, that we can use with alternate
+ backend, or for stand-alone test cases.
+ """
+
def write_no_block(self, data: bytes) -> None:
raise NotImplementedError() # pragma: no cover
class BasePoolSemaphore:
+ """
+ A semaphore for use with connection pooling.
+
+ Abstracts away any asyncio-specfic interfaces.
+ """
+
async def acquire(self) -> None:
raise NotImplementedError() # pragma: no cover