From: Yeray Diaz Diaz Date: Mon, 29 Apr 2019 12:38:36 +0000 (+0100) Subject: Raise single DecodingError X-Git-Tag: 0.3.0~65^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b4742303e215ce72e062cf408982e06f50b2c86;p=thirdparty%2Fhttpx.git Raise single DecodingError Fix typo --- diff --git a/httpcore/__init__.py b/httpcore/__init__.py index 7786c259..a6e4db97 100644 --- a/httpcore/__init__.py +++ b/httpcore/__init__.py @@ -9,9 +9,7 @@ from .exceptions import ( ResponseClosed, StreamConsumed, Timeout, - DeflateDecodingError, - GzipDecodingError, - BrotliDecodingError, + DecodingError, ) from .http11 import HTTP11Connection from .sync import SyncClient, SyncConnectionPool diff --git a/httpcore/decoders.py b/httpcore/decoders.py index dc56e131..4636b0f4 100644 --- a/httpcore/decoders.py +++ b/httpcore/decoders.py @@ -45,13 +45,13 @@ class DeflateDecoder(Decoder): 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): @@ -68,13 +68,13 @@ 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): @@ -95,19 +95,19 @@ 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: diff --git a/httpcore/exceptions.py b/httpcore/exceptions.py index a85f128f..9756a54f 100644 --- a/httpcore/exceptions.py +++ b/httpcore/exceptions.py @@ -46,21 +46,3 @@ class DecodingError(Exception): """ 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. - """ diff --git a/tests/test_decoding.py b/tests/test_decoding.py index c4a17466..0ed7e668 100644 --- a/tests/test_decoding.py +++ b/tests/test_decoding.py @@ -79,16 +79,10 @@ async def test_streaming(): 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)