@@ -69,9 +69,15 @@ def _remove_closed_connections(self) -> None:
6969 if conn .is_closed ():
7070 self ._connections .remove (conn )
7171
72+ def description (self ) -> str :
73+ counts = {"active" : 0 }
74+ for status in [c .description () for c in self ._connections ]:
75+ counts [status ] = counts .get (status , 0 ) + 1
76+ return ", " .join (f"{ count } { status } " for status , count in counts .items ())
77+
7278 # Builtins...
7379 def __repr__ (self ) -> str :
74- return f"<ConectionPool { self ._connections !r } > "
80+ return f"<ConectionPool [ { self .description () } ]] "
7581
7682 def __enter__ (self ) -> "ConnectionPool" :
7783 return self
@@ -107,6 +113,18 @@ def is_expired(self, when: float):
107113 def is_closed (self ):
108114 return self ._state .our_state in (h11 .CLOSED , h11 .ERROR )
109115
116+ def description (self ):
117+ return {
118+ h11 .IDLE : "idle" ,
119+ h11 .SEND_BODY : "active" ,
120+ h11 .DONE : "active" ,
121+ h11 .MUST_CLOSE : "closing" ,
122+ h11 .CLOSED : "closed" ,
123+ h11 .ERROR : "error" ,
124+ h11 .MIGHT_SWITCH_PROTOCOL : "upgrading" ,
125+ h11 .SWITCHED_PROTOCOL : "upgraded" ,
126+ }[self ._state .our_state ]
127+
110128 # API entry points...
111129 @contextlib .asynccontextmanager
112130 async def send (self , request : Request ) -> typing .AsyncIterator [Response ]:
@@ -189,7 +207,7 @@ async def _close(self):
189207
190208 # Builtins...
191209 def __repr__ (self ):
192- return f"<Connection [{ str (self ._origin )} , { self ._state . our_state } ]>"
210+ return f"<Connection [{ str (self ._origin )} , { self .description () } ]>"
193211
194212 async def __aenter__ (self ) -> "Connection" :
195213 return self
0 commit comments