try:
return self.decompressor.decompress(data)
except zlib.error as exc:
- raise httpcore.exceptions.DeflateDecodingError from exc
+ raise httpcore.exceptions.DecodingError from exc
def flush(self) -> bytes:
try:
return self.decompressor.flush()
except zlib.error as exc:
- raise httpcore.exceptions.DeflateDecodingError from exc
+ raise httpcore.exceptions.DecodingError from exc
class GZipDecoder(Decoder):
try:
return self.decompressor.decompress(data)
except zlib.error as exc:
- raise httpcore.exceptions.GzipDecodingError from exc
+ raise httpcore.exceptions.DecodingError from exc
def flush(self) -> bytes:
try:
return self.decompressor.flush()
except zlib.error as exc:
- raise httpcore.exceptions.GzipDecodingError from exc
+ raise httpcore.exceptions.DecodingError from exc
class BrotliDecoder(Decoder):
try:
return self.decompressor.decompress(data)
except brotli.Error as exc:
- raise httpcore.exceptions.BrotliDecodingError from exc
+ raise httpcore.exceptions.DecodingError from exc
def flush(self) -> bytes:
try:
self.decompressor.finish()
return b""
except brotli.Error as exc:
- raise httpcore.exceptions.BrotliDecodingError from exc
+ raise httpcore.exceptions.DecodingError from exc
class MultiDecoder(Decoder):
"""
- Handle the case where mutiple encodings have been applied.
+ Handle the case where multiple encodings have been applied.
"""
def __init__(self, children: typing.Sequence[Decoder]) -> None:
"""
Decoding of the response failed.
"""
-
-
-class DeflateDecodingError(DecodingError):
- """
- Decoding of the response using deflate failed.
- """
-
-
-class GzipDecodingError(DecodingError):
- """
- Decoding of the response using gzip failed.
- """
-
-
-class BrotliDecodingError(DecodingError):
- """
- Decoding of the response using brotli failed.
- """
assert await response.read() == body
-@pytest.mark.parametrize(
- 'header_value, expected_exception',
- [
- (b"deflate", httpcore.DeflateDecodingError),
- (b"gzip", httpcore.GzipDecodingError),
- (b"br", httpcore.BrotliDecodingError),
- ])
-def test_decoding_errors(header_value, expected_exception):
+@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))
+def test_decoding_errors(header_value):
headers = [(b"Content-Encoding", header_value)]
body = b"test 123"
compressed_body = brotli.compress(body)[3:]
- with pytest.raises(expected_exception):
+ with pytest.raises(httpcore.exceptions.DecodingError):
response = httpcore.Response(200, headers=headers, body=compressed_body)