Raise single DecodingError
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix typo
authored by Yeray Diaz Diaz · committed by Yeray Diaz Diaz · parent bdc218f · Browse files · 4 files·+11 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+11 added−37 removed
- tests:+3 added−9 removed
- other:+8 added−28 removed
Provenance
- Commit
6b47423- Tree
ae511d8- Author
Yeray Diaz Diaz <yeray.diaz@farfetch.com>- Committer
Yeray Diaz Diaz <yeray.diaz@farfetch.com>- Parent
bdc218f
4 files changed+11 added−37 removed
modified:httpcore/__init__.py+1 added-3 removed
7 unmodified lines8 ReadTimeout,9 ResponseClosed,10 StreamConsumed,11 Timeout,12- DeflateDecodingError,13- GzipDecodingError,14- BrotliDecodingError,12+ DecodingError,13 )14 from .http11 import HTTP11Connection15 from .sync import SyncClient, SyncConnectionPool16 1 unmodified linemodified:httpcore/decoders.py+7 added-7 removed
43 unmodified lines44 def decode(self, data: bytes) -> bytes:45 try:46 return self.decompressor.decompress(data)47 except zlib.error as exc:48- raise httpcore.exceptions.DeflateDecodingError from exc48+ raise httpcore.exceptions.DecodingError from exc49 50 def flush(self) -> bytes:51 try:52 return self.decompressor.flush()53 except zlib.error as exc:54- raise httpcore.exceptions.DeflateDecodingError from exc54+ raise httpcore.exceptions.DecodingError from exc55 56 57 class GZipDecoder(Decoder):58 """8 unmodified lines67 def decode(self, data: bytes) -> bytes:68 try:69 return self.decompressor.decompress(data)70 except zlib.error as exc:71- raise httpcore.exceptions.GzipDecodingError from exc71+ raise httpcore.exceptions.DecodingError from exc72 73 def flush(self) -> bytes:74 try:75 return self.decompressor.flush()76 except zlib.error as exc:77- raise httpcore.exceptions.GzipDecodingError from exc77+ raise httpcore.exceptions.DecodingError from exc78 79 80 class BrotliDecoder(Decoder):81 """12 unmodified lines94 def decode(self, data: bytes) -> bytes:95 try:96 return self.decompressor.decompress(data)97 except brotli.Error as exc:98- raise httpcore.exceptions.BrotliDecodingError from exc98+ raise httpcore.exceptions.DecodingError from exc99 100 def flush(self) -> bytes:101 try:102 self.decompressor.finish()103 return b""104 except brotli.Error as exc:105- raise httpcore.exceptions.BrotliDecodingError from exc105+ raise httpcore.exceptions.DecodingError from exc106 107 108 class MultiDecoder(Decoder):109 """110- Handle the case where mutiple encodings have been applied.110+ Handle the case where multiple encodings have been applied.111 """112 113 def __init__(self, children: typing.Sequence[Decoder]) -> None:114 """33 unmodified linesmodified:httpcore/exceptions.py-18 removed
44 unmodified lines45 class DecodingError(Exception):46 """47 Decoding of the response failed.48 """49-50-51-class DeflateDecodingError(DecodingError):52- """53- Decoding of the response using deflate failed.54- """55-56-57-class GzipDecodingError(DecodingError):58- """59- Decoding of the response using gzip failed.60- """61-62-63-class BrotliDecodingError(DecodingError):64- """65- Decoding of the response using brotli failed.66- """modified:tests/test_decoding.py+3 added-9 removed
77 unmodified lines78 assert not hasattr(response, "body")79 assert await response.read() == body80 81 82-@pytest.mark.parametrize(83- 'header_value, expected_exception',84- [85- (b"deflate", httpcore.DeflateDecodingError),86- (b"gzip", httpcore.GzipDecodingError),87- (b"br", httpcore.BrotliDecodingError),88- ])89-def test_decoding_errors(header_value, expected_exception):82+@pytest.mark.parametrize("header_value", (b"deflate", b"gzip", b"br"))83+def test_decoding_errors(header_value):84 headers = [(b"Content-Encoding", header_value)]85 body = b"test 123"86 compressed_body = brotli.compress(body)[3:]93- with pytest.raises(expected_exception):87+ with pytest.raises(httpcore.exceptions.DecodingError):88 response = httpcore.Response(200, headers=headers, body=compressed_body)