5
5
import platform
6
6
import sys
7
7
from json import JSONDecodeError
8
- from typing import Any , Callable , Dict , List , NamedTuple , Optional , Set , Union , cast
8
+ from typing import Any , Callable , NamedTuple , Optional , Union , cast
9
9
10
10
import click
11
11
import typer
@@ -55,10 +55,10 @@ class TokenSet(NamedTuple):
55
55
# there isn't a matching dependent scope, that means we need to prompt for consent
56
56
# again. If there is a matching full-scope-string in `dependent_scopes`, then we're
57
57
# OK to use the token from looking up that base scope.
58
- dependent_scopes : Set [str ]
58
+ dependent_scopes : set [str ]
59
59
60
60
61
- TokensInTokenCache = Dict [str , Union [TokenSet , Dict [str , TokenSet ]]]
61
+ TokensInTokenCache = dict [str , Union [TokenSet , dict [str , TokenSet ]]]
62
62
63
63
64
64
class TokenCache :
@@ -81,7 +81,7 @@ def tokens_for_environment(self):
81
81
return self .tokens
82
82
environ_cache_key = TokenCache ._environment_prefix + environ
83
83
if environ_cache_key not in self .tokens :
84
- self .tokens [environ_cache_key ]: Dict [str , TokenSet ] = {}
84
+ self .tokens [environ_cache_key ]: dict [str , TokenSet ] = {}
85
85
return self .tokens [environ_cache_key ]
86
86
87
87
def set_tokens (self , scope : str , tokens : TokenSet ) -> TokenSet :
@@ -115,7 +115,7 @@ def get_tokens(self, scope: str) -> Optional[TokenSet]:
115
115
return self .tokens_for_environment .get (scope )
116
116
117
117
@staticmethod
118
- def _deserialize_from_file (file_tokens : Dict [str , Any ]) -> TokensInTokenCache :
118
+ def _deserialize_from_file (file_tokens : dict [str , Any ]) -> TokensInTokenCache :
119
119
deserialized : TokensInTokenCache = {}
120
120
for k , v in file_tokens .items ():
121
121
if k .startswith (TokenCache ._environment_prefix ):
@@ -142,8 +142,8 @@ def load_tokens(self):
142
142
)
143
143
144
144
@staticmethod
145
- def _make_jsonable (tokens ) -> Dict [str , Any ]:
146
- serialized : Dict [str , Any ] = {}
145
+ def _make_jsonable (tokens ) -> dict [str , Any ]:
146
+ serialized : dict [str , Any ] = {}
147
147
for k , v in tokens .items ():
148
148
if isinstance (v , TokenSet ):
149
149
v = v ._asdict ()
@@ -194,10 +194,10 @@ def clear_tokens(
194
194
self .modified = True
195
195
196
196
def update_from_oauth_token_response (
197
- self , token_response : OAuthTokenResponse , original_scopes : Set [str ]
198
- ) -> Dict [str , TokenSet ]:
197
+ self , token_response : OAuthTokenResponse , original_scopes : set [str ]
198
+ ) -> dict [str , TokenSet ]:
199
199
by_scopes = token_response .by_scopes
200
- token_sets : Dict [str , TokenSet ] = {}
200
+ token_sets : dict [str , TokenSet ] = {}
201
201
for scope in by_scopes :
202
202
token_info = by_scopes [scope ]
203
203
dependent_scopes = {s for s in original_scopes if "[" in s }
@@ -237,7 +237,7 @@ def safeprint(s, err: bool = False):
237
237
238
238
239
239
def _do_login_for_scopes (
240
- native_client : NativeAppAuthClient , scopes : List [str ]
240
+ native_client : NativeAppAuthClient , scopes : list [str ]
241
241
) -> OAuthTokenResponse :
242
242
label = CLIENT_NAME
243
243
host = platform .node ()
@@ -269,17 +269,17 @@ def refresh_handler(response: OAuthTokenResponse, *args, **kwargs):
269
269
270
270
271
271
def get_authorizers_for_scopes (
272
- scopes : List [str ],
272
+ scopes : list [str ],
273
273
token_store : Optional [Union [pathlib .Path , str ]] = None ,
274
274
client_id : str = CLIENT_ID ,
275
275
client_name : str = CLIENT_NAME ,
276
276
no_login : bool = False ,
277
- ) -> Dict [str , GlobusAuthorizer ]:
277
+ ) -> dict [str , GlobusAuthorizer ]:
278
278
token_store = token_store or str (DEFAULT_TOKEN_FILE )
279
279
token_cache = TokenCache (token_store )
280
280
token_cache .load_tokens ()
281
- token_sets : Dict [str , TokenSet ] = {}
282
- needed_scopes : Set [str ] = set ()
281
+ token_sets : dict [str , TokenSet ] = {}
282
+ needed_scopes : set [str ] = set ()
283
283
native_client = _get_globus_sdk_native_client (client_id , client_name )
284
284
285
285
for scope in scopes :
@@ -296,7 +296,7 @@ def get_authorizers_for_scopes(
296
296
)
297
297
token_sets .update (new_tokens )
298
298
299
- authorizers : Dict [str , GlobusAuthorizer ] = {}
299
+ authorizers : dict [str , GlobusAuthorizer ] = {}
300
300
for scope , token_set in token_sets .items ():
301
301
if token_set is not None :
302
302
authorizer : Union [RefreshTokenAuthorizer , AccessTokenAuthorizer ]
@@ -362,7 +362,7 @@ def revoker(scope: str, token_set: TokenSet) -> bool:
362
362
363
363
def get_current_user (
364
364
no_login : bool = False , token_store : Union [pathlib .Path , str ] = DEFAULT_TOKEN_FILE
365
- ) -> Optional [Dict [str , Any ]]:
365
+ ) -> Optional [dict [str , Any ]]:
366
366
"""
367
367
When `no_login` is set, returns `None` if not logged in.
368
368
"""
0 commit comments