2323
2424from .facade_versions import client_facade_versions , known_unsupported_facades
2525
26+ LEVELS = ["TRACE" , "DEBUG" , "INFO" , "WARNING" , "ERROR" ]
2627log = logging .getLogger ("juju.client.connection" )
2728
2829
@@ -240,7 +241,7 @@ async def connect(
240241 if isinstance (endpoint , str )
241242 else [(e , cacert ) for e in endpoint ]
242243 )
243- lastError = None
244+ last_error = None
244245 for _ep in _endpoints :
245246 try :
246247 if self .is_debug_log_connection :
@@ -251,14 +252,14 @@ async def connect(
251252 await self ._connect_with_redirect ([_ep ])
252253 return self
253254 except ssl .SSLError as e :
254- lastError = e
255+ last_error = e
255256 continue
256257 except OSError as e :
257258 logging .debug (f"Cannot access endpoint { _ep } : { e .strerror } " )
258- lastError = e
259+ last_error = e
259260 continue
260- if lastError is not None :
261- raise lastError
261+ if last_error is not None :
262+ raise last_error
262263 raise Exception ("Unable to connect to websocket" )
263264
264265 @property
@@ -407,7 +408,6 @@ def debug_log_filter_write(self, result):
407408 and (included_entities == [] or entity in included_entities )
408409 )
409410
410- LEVELS = ["TRACE" , "DEBUG" , "INFO" , "WARNING" , "ERROR" ]
411411 log_level = self .debug_log_params ["level" ]
412412
413413 if log_level != "" and log_level not in LEVELS :
@@ -595,10 +595,11 @@ async def rpc(self, msg, encoder=None):
595595 # Perhaps JujuError should return all the results including
596596 # errors, or perhaps a keyword parameter to the rpc method
597597 # could be added to trigger this behaviour.
598- err_results = []
599- for res in result ["response" ]["results" ] or []:
600- if res .get ("error" , {}).get ("message" ):
601- err_results .append (res ["error" ]["message" ])
598+ err_results = [
599+ res ["error" ]["message" ]
600+ for res in (result ["response" ]["results" ] or [])
601+ if res .get ("error" , {}).get ("message" )
602+ ]
602603 if err_results :
603604 raise errors .JujuError (err_results )
604605
@@ -781,14 +782,14 @@ async def _connect_with_login(self, endpoints):
781782 # It's possible that we may get several discharge-required errors,
782783 # corresponding to different levels of authentication, so retry
783784 # a few times.
784- for i in range (0 , 2 ):
785+ for _ in range (0 , 2 ):
785786 result = (await self .login ())["response" ]
786- macaroonJSON = result .get ("discharge-required" )
787- if macaroonJSON is None :
787+ macaroon_json = result .get ("discharge-required" )
788+ if macaroon_json is None :
788789 self .info = result
789790 success = True
790791 return result
791- macaroon = bakery .Macaroon .from_dict (macaroonJSON )
792+ macaroon = bakery .Macaroon .from_dict (macaroon_json )
792793 self .bakery_client .handle_error (
793794 httpbakery .Error (
794795 code = httpbakery .ERR_DISCHARGE_REQUIRED ,
0 commit comments