2727from .facade_versions import client_facade_versions , known_unsupported_facades
2828
2929SpecifiedFacades : TypeAlias = "dict[str, dict[Literal['versions'], Sequence[int]]]"
30- _WebSocket : TypeAlias = " websockets.legacy.client. WebSocketClientProtocol"
30+ _WebSocket : TypeAlias = websockets .WebSocketClientProtocol
3131
3232LEVELS = ["TRACE" , "DEBUG" , "INFO" , "WARNING" , "ERROR" ]
3333log = logging .getLogger ("juju.client.connection" )
@@ -291,7 +291,7 @@ def is_using_old_client(self):
291291 def is_open (self ):
292292 return self .monitor .status == Monitor .CONNECTED
293293
294- def _get_ssl (self , cert = None ):
294+ def _get_ssl (self , cert : str | None = None ) -> ssl . SSLContext :
295295 context = ssl .create_default_context (
296296 purpose = ssl .Purpose .SERVER_AUTH , cadata = cert
297297 )
@@ -305,7 +305,9 @@ def _get_ssl(self, cert=None):
305305 context .check_hostname = False
306306 return context
307307
308- async def _open (self , endpoint , cacert ) -> tuple [_WebSocket , str , str , str ]:
308+ async def _open (
309+ self , endpoint : str , cacert : str
310+ ) -> tuple [_WebSocket , str , str , str ]:
309311 if self .is_debug_log_connection :
310312 assert self .uuid
311313 url = f"wss://user-{ self .username } :{ self .password } @{ endpoint } /model/{ self .uuid } /log"
@@ -323,10 +325,6 @@ async def _open(self, endpoint, cacert) -> tuple[_WebSocket, str, str, str]:
323325 sock = self .proxy .socket ()
324326 server_hostname = "juju-app"
325327
326- def _exit_tasks ():
327- for task in jasyncio .all_tasks ():
328- task .cancel ()
329-
330328 return (
331329 (
332330 await websockets .connect (
@@ -342,7 +340,7 @@ def _exit_tasks():
342340 cacert ,
343341 )
344342
345- async def close (self , to_reconnect = False ):
343+ async def close (self , to_reconnect : bool = False ):
346344 if not self ._ws :
347345 return
348346 self .monitor .close_called .set ()
@@ -380,11 +378,7 @@ async def close(self, to_reconnect=False):
380378
381379 async def _recv (self , request_id : int ) -> dict [str , Any ]:
382380 if not self .is_open :
383- raise websockets .exceptions .ConnectionClosed (
384- websockets .frames .Close (
385- websockets .frames .CloseCode .NORMAL_CLOSURE , "websocket closed"
386- )
387- )
381+ raise websockets .exceptions .ConnectionClosedOK (None , None )
388382 try :
389383 return await self .messages .get (request_id )
390384 except GeneratorExit :
@@ -626,7 +620,7 @@ async def rpc(
626620
627621 return result
628622
629- def _http_headers (self ):
623+ def _http_headers (self ) -> dict [ str , str ] :
630624 """Return dictionary of http headers necessary for making an http
631625 connection to the endpoint of this Connection.
632626
@@ -640,7 +634,7 @@ def _http_headers(self):
640634 token = base64 .b64encode (creds .encode ())
641635 return {"Authorization" : f"Basic { token .decode ()} " }
642636
643- def https_connection (self ):
637+ def https_connection (self ) -> tuple [ HTTPSConnection , dict [ str , str ], str ] :
644638 """Return an https connection to this Connection's endpoint.
645639
646640 Returns a 3-tuple containing::
0 commit comments