]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Raise single DecodingError
authorYeray Diaz Diaz <yeray.diaz@farfetch.com>
Mon, 29 Apr 2019 12:38:36 +0000 (13:38 +0100)
committerYeray Diaz Diaz <yeray.diaz@farfetch.com>
Mon, 29 Apr 2019 12:38:36 +0000 (13:38 +0100)
Fix typo

httpcore/__init__.py
httpcore/decoders.py
httpcore/exceptions.py
tests/test_decoding.py

index 7786c2595951b591e0c293abf2e1a33fd141de13..a6e4db97630703d96f6a2865b0a741aebbb2e24c 100644 (file)
@@ -9,9 +9,7 @@ from .exceptions import (
     ResponseClosed,
     StreamConsumed,
     Timeout,
-    DeflateDecodingError,
-    GzipDecodingError,
-    BrotliDecodingError,
+    DecodingError,
 )
 from .http11 import HTTP11Connection
 from .sync import SyncClient, SyncConnectionPool
index dc56e1315803f93261ca633f6d5384fef39127a4..4636b0f4d78a61b3c5a6261c146c6985d698196c 100644 (file)
@@ -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:
index a85f128fa9a5541cab8fb8a5ab3302f83b68c9c5..9756a54f074aed8fd7c144697c92f24c6b830736 100644 (file)
@@ -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.
-    """
index c4a174667c03b05c8db36b8579f34f96e7f334e1..0ed7e668eeb106276f5902ebac8e373008247e78 100644 (file)
@@ -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)