diff --git a/src/ahttpx/_client.py b/src/ahttpx/_client.py index 61a3977..777936d 100644 --- a/src/ahttpx/_client.py +++ b/src/ahttpx/_client.py @@ -106,7 +106,7 @@ async def close(self): await self.transport.close() def __repr__(self): - return "" + return f"" class RedirectMiddleware: diff --git a/src/ahttpx/_pool.py b/src/ahttpx/_pool.py index de00ac8..fdd73fe 100644 --- a/src/ahttpx/_pool.py +++ b/src/ahttpx/_pool.py @@ -69,9 +69,15 @@ def _remove_closed_connections(self) -> None: if conn.is_closed(): self._connections.remove(conn) + def description(self) -> str: + counts = {"active": 0} + for status in [c.description() for c in self._connections]: + counts[status] = counts.get(status, 0) + 1 + return ", ".join(f"{count} {status}" for status, count in counts.items()) + # Builtins... def __repr__(self) -> str: - return f"" + return f" "ConnectionPool": return self @@ -107,6 +113,18 @@ def is_expired(self, when: float): def is_closed(self): return self._state.our_state in (h11.CLOSED, h11.ERROR) + def description(self): + return { + h11.IDLE: "idle", + h11.SEND_BODY: "active", + h11.DONE: "active", + h11.MUST_CLOSE: "closing", + h11.CLOSED: "closed", + h11.ERROR: "error", + h11.MIGHT_SWITCH_PROTOCOL: "upgrading", + h11.SWITCHED_PROTOCOL: "upgraded", + }[self._state.our_state] + # API entry points... @contextlib.asynccontextmanager async def send(self, request: Request) -> typing.AsyncIterator[Response]: @@ -189,7 +207,7 @@ async def _close(self): # Builtins... def __repr__(self): - return f"" + return f"" async def __aenter__(self) -> "Connection": return self diff --git a/src/httpx/_client.py b/src/httpx/_client.py index ee61eaf..0e92f04 100644 --- a/src/httpx/_client.py +++ b/src/httpx/_client.py @@ -106,7 +106,7 @@ def close(self): self.transport.close() def __repr__(self): - return "" + return f"" class RedirectMiddleware: diff --git a/src/httpx/_pool.py b/src/httpx/_pool.py index 9ba55cc..9f9859b 100644 --- a/src/httpx/_pool.py +++ b/src/httpx/_pool.py @@ -69,9 +69,15 @@ def _remove_closed_connections(self) -> None: if conn.is_closed(): self._connections.remove(conn) + def description(self) -> str: + counts = {"active": 0} + for status in [c.description() for c in self._connections]: + counts[status] = counts.get(status, 0) + 1 + return ", ".join(f"{count} {status}" for status, count in counts.items()) + # Builtins... def __repr__(self) -> str: - return f"" + return f" "ConnectionPool": return self @@ -107,6 +113,18 @@ def is_expired(self, when: float): def is_closed(self): return self._state.our_state in (h11.CLOSED, h11.ERROR) + def description(self): + return { + h11.IDLE: "idle", + h11.SEND_BODY: "active", + h11.DONE: "active", + h11.MUST_CLOSE: "closing", + h11.CLOSED: "closed", + h11.ERROR: "error", + h11.MIGHT_SWITCH_PROTOCOL: "upgrading", + h11.SWITCHED_PROTOCOL: "upgraded", + }[self._state.our_state] + # API entry points... @contextlib.contextmanager def send(self, request: Request) -> typing.Iterator[Response]: @@ -189,7 +207,7 @@ def _close(self): # Builtins... def __repr__(self): - return f"" + return f"" def __enter__(self) -> "Connection": return self