Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ahttpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def close(self):
await self.transport.close()

def __repr__(self):
return "<Client>"
return f"<Client [{self.transport.description()}]>"


class RedirectMiddleware:
Expand Down
22 changes: 20 additions & 2 deletions src/ahttpx/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<ConectionPool {self._connections!r}>"
return f"<ConectionPool [{self.description()}]]"

def __enter__(self) -> "ConnectionPool":
return self
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -189,7 +207,7 @@ async def _close(self):

# Builtins...
def __repr__(self):
return f"<Connection [{str(self._origin)}, {self._state.our_state}]>"
return f"<Connection [{str(self._origin)}, {self.description()}]>"

async def __aenter__(self) -> "Connection":
return self
Expand Down
2 changes: 1 addition & 1 deletion src/httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def close(self):
self.transport.close()

def __repr__(self):
return "<Client>"
return f"<Client [{self.transport.description()}]>"


class RedirectMiddleware:
Expand Down
22 changes: 20 additions & 2 deletions src/httpx/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<ConectionPool {self._connections!r}>"
return f"<ConectionPool [{self.description()}]]"

def __enter__(self) -> "ConnectionPool":
return self
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -189,7 +207,7 @@ def _close(self):

# Builtins...
def __repr__(self):
return f"<Connection [{str(self._origin)}, {self._state.our_state}]>"
return f"<Connection [{str(self._origin)}, {self.description()}]>"

def __enter__(self) -> "Connection":
return self
Expand Down
Loading