Skip to content
Myr

`httpx.ResponseClosed` -> `httpx.StreamClosed` (#1584)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* ResponseClosed -> StreamClosed * Update docs for StreamClosed

authored by Tom Christie · committed by GitHub · parent 6a99f6f · Browse files · 5 files+24 added−25 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+24 added−25 removed

  • tests:+2 added−2 removed
  • other:+22 added−23 removed

5 files+24 added−25 removed

modified:docs/exceptions.md+3 added-3 removed
modified:httpx/__init__.py+2 added-2 removed
21 unmodified lines
22 ReadTimeout,23 RemoteProtocolError,24 RequestError,25 RequestNotRead,26 ResponseClosed,26 ResponseNotRead,27 StreamClosed,28 StreamConsumed,29 StreamError,30 TimeoutException,31 TooManyRedirects,
66 unmodified lines
98 "Request",99 "RequestError",100 "RequestNotRead",101 "Response",102 "ResponseClosed",102 "ResponseNotRead",103 "StatusCode",104 "stream",105 "StreamClosed",106 "StreamConsumed",107 "StreamError",108 "SyncByteStream",109 "Timeout",
15 unmodified lines
modified:httpx/_exceptions.py+14 added-15 removed
25 unmodified lines
26* InvalidURL27* CookieConflict28* StreamError29 x StreamConsumed30 x StreamClosed31 x ResponseNotRead32 x RequestNotRead32 x ResponseClosed33"""34import contextlib35import typing36
224 unmodified lines
261# These may occur as the result of a programming error, by accessing262# the request/response stream in an invalid manner.263264265class StreamError(Exception):265class StreamError(RuntimeError):266 """267 The base class for stream exceptions.268269 The developer made an error in accessing the request stream in
21 unmodified lines
291 )292 super().__init__(message)293294295class ResponseNotRead(StreamError):295class StreamClosed(StreamError):296 """297 Attempted to access streaming response content, without having called `read()`.297 Attempted to read or stream response content, but the request has been298 closed.299 """300301 def __init__(self) -> None:301 message = "Attempted to access streaming response content, without having called `read()`."302 message = (303 "Attempted to read or stream content, but the stream has " "been closed."304 )305 super().__init__(message)306307305class RequestNotRead(StreamError):308class ResponseNotRead(StreamError):309 """307 Attempted to access streaming request content, without having called `read()`.310 Attempted to access streaming response content, without having called `read()`.311 """312313 def __init__(self) -> None:311 message = "Attempted to access streaming request content, without having called `read()`."314 message = "Attempted to access streaming response content, without having called `read()`."315 super().__init__(message)316317315class ResponseClosed(StreamError):318class RequestNotRead(StreamError):319 """317 Attempted to read or stream response content, but the request has been318 closed.320 Attempted to access streaming request content, without having called `read()`.321 """322323 def __init__(self) -> None:322 message = (323 "Attempted to read or stream response content, but the request has "324 "been closed."325 )324 message = "Attempted to access streaming request content, without having called `read()`."325 super().__init__(message)326327328@contextlib.contextmanager
11 unmodified lines
modified:httpx/_models.py+3 added-3 removed
25 unmodified lines
26 CookieConflict,27 HTTPStatusError,28 InvalidURL,29 RequestNotRead,30 ResponseClosed,30 ResponseNotRead,31 StreamClosed,32 StreamConsumed,33 request_context,34)35from ._status_codes import codes
1185 unmodified lines
1221 """1222 if self.is_stream_consumed:1223 raise StreamConsumed()1224 if self.is_closed:1225 raise ResponseClosed()1225 raise StreamClosed()1226 if not isinstance(self.stream, SyncByteStream):1227 raise RuntimeError("Attempted to call a sync iterator on an async stream.")12281229 self.is_stream_consumed = True
89 unmodified lines
1319 """1320 if self.is_stream_consumed:1321 raise StreamConsumed()1322 if self.is_closed:1323 raise ResponseClosed()1323 raise StreamClosed()1324 if not isinstance(self.stream, AsyncByteStream):1325 raise RuntimeError("Attempted to call an async iterator on an sync stream.")13261327 self.is_stream_consumed = True
217 unmodified lines
modified:tests/models/test_responses.py+2 added-2 removed
658 unmodified lines
659 content=streaming_body(),660 )661662 response.close()663 with pytest.raises(httpx.ResponseClosed):663 with pytest.raises(httpx.StreamClosed):664 response.read()665666667@pytest.mark.asyncio
3 unmodified lines
671 content=async_streaming_body(),672 )673674 await response.aclose()675 with pytest.raises(httpx.ResponseClosed):675 with pytest.raises(httpx.StreamClosed):676 await response.aread()677678679@pytest.mark.asyncio
176 unmodified lines