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

* ResponseClosed -> StreamClosed

* Update docs for StreamClosed
This commit is contained in:
Tom Christie 2021-04-21 10:51:35 +01:00 committed by GitHub
parent 6a99f6f2b3
commit 9b8f5af759
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 26 deletions

View File

@ -162,11 +162,11 @@ except httpx.HTTPStatusError as exc:
::: httpx.StreamConsumed
:docstring:
::: httpx.StreamClosed
:docstring:
::: httpx.ResponseNotRead
:docstring:
::: httpx.RequestNotRead
:docstring:
::: httpx.ResponseClosed
:docstring:

View File

@ -23,8 +23,8 @@ from ._exceptions import (
RemoteProtocolError,
RequestError,
RequestNotRead,
ResponseClosed,
ResponseNotRead,
StreamClosed,
StreamConsumed,
StreamError,
TimeoutException,
@ -99,10 +99,10 @@ __all__ = [
"RequestError",
"RequestNotRead",
"Response",
"ResponseClosed",
"ResponseNotRead",
"StatusCode",
"stream",
"StreamClosed",
"StreamConsumed",
"StreamError",
"SyncByteStream",

View File

@ -27,9 +27,9 @@ Our exception hierarchy:
* CookieConflict
* StreamError
x StreamConsumed
x StreamClosed
x ResponseNotRead
x RequestNotRead
x ResponseClosed
"""
import contextlib
import typing
@ -262,7 +262,7 @@ class CookieConflict(Exception):
# the request/response stream in an invalid manner.
class StreamError(Exception):
class StreamError(RuntimeError):
"""
The base class for stream exceptions.
@ -292,6 +292,19 @@ class StreamConsumed(StreamError):
super().__init__(message)
class StreamClosed(StreamError):
"""
Attempted to read or stream response content, but the request has been
closed.
"""
def __init__(self) -> None:
message = (
"Attempted to read or stream content, but the stream has " "been closed."
)
super().__init__(message)
class ResponseNotRead(StreamError):
"""
Attempted to access streaming response content, without having called `read()`.
@ -312,20 +325,6 @@ class RequestNotRead(StreamError):
super().__init__(message)
class ResponseClosed(StreamError):
"""
Attempted to read or stream response content, but the request has been
closed.
"""
def __init__(self) -> None:
message = (
"Attempted to read or stream response content, but the request has "
"been closed."
)
super().__init__(message)
@contextlib.contextmanager
def request_context(request: "Request" = None) -> typing.Iterator[None]:
"""

View File

@ -27,8 +27,8 @@ from ._exceptions import (
HTTPStatusError,
InvalidURL,
RequestNotRead,
ResponseClosed,
ResponseNotRead,
StreamClosed,
StreamConsumed,
request_context,
)
@ -1222,7 +1222,7 @@ class Response:
if self.is_stream_consumed:
raise StreamConsumed()
if self.is_closed:
raise ResponseClosed()
raise StreamClosed()
if not isinstance(self.stream, SyncByteStream):
raise RuntimeError("Attempted to call a sync iterator on an async stream.")
@ -1320,7 +1320,7 @@ class Response:
if self.is_stream_consumed:
raise StreamConsumed()
if self.is_closed:
raise ResponseClosed()
raise StreamClosed()
if not isinstance(self.stream, AsyncByteStream):
raise RuntimeError("Attempted to call an async iterator on an sync stream.")

View File

@ -660,7 +660,7 @@ def test_cannot_read_after_response_closed():
)
response.close()
with pytest.raises(httpx.ResponseClosed):
with pytest.raises(httpx.StreamClosed):
response.read()
@ -672,7 +672,7 @@ async def test_cannot_aread_after_response_closed():
)
await response.aclose()
with pytest.raises(httpx.ResponseClosed):
with pytest.raises(httpx.StreamClosed):
await response.aread()