Skip to content

Commit a507a16

Browse files
committed
chore: fix src lint
1 parent 4d58c78 commit a507a16

21 files changed

+345
-362
lines changed

firebase_admin/__init__.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def initialize_app(credential=None, options=None, name=_DEFAULT_APP_NAME):
7979
'apps, pass a second argument to initialize_app() to give each app '
8080
'a unique name.'))
8181

82-
raise ValueError((
83-
'Firebase app named "{0}" already exists. This means you called '
82+
raise ValueError(
83+
f'Firebase app named "{name}" already exists. This means you called '
8484
'initialize_app() more than once with the same app name as the '
8585
'second argument. Make sure you provide a unique name every time '
86-
'you call initialize_app().').format(name))
86+
'you call initialize_app().')
8787

8888

8989
def delete_app(app):
@@ -96,8 +96,7 @@ def delete_app(app):
9696
ValueError: If the app is not initialized.
9797
"""
9898
if not isinstance(app, App):
99-
raise ValueError('Illegal app argument type: "{}". Argument must be of '
100-
'type App.'.format(type(app)))
99+
raise ValueError(f'Illegal app argument type: "{type(app)}". Argument must be of type App.')
101100
with _apps_lock:
102101
if _apps.get(app.name) is app:
103102
del _apps[app.name]
@@ -109,9 +108,9 @@ def delete_app(app):
109108
'the default app by calling initialize_app().')
110109

111110
raise ValueError(
112-
('Firebase app named "{0}" is not initialized. Make sure to initialize '
113-
'the app by calling initialize_app() with your app name as the '
114-
'second argument.').format(app.name))
111+
f'Firebase app named "{app.name}" is not initialized. Make sure to initialize '
112+
'the app by calling initialize_app() with your app name as the '
113+
'second argument.')
115114

116115

117116
def get_app(name=_DEFAULT_APP_NAME):
@@ -128,8 +127,8 @@ def get_app(name=_DEFAULT_APP_NAME):
128127
app does not exist.
129128
"""
130129
if not isinstance(name, str):
131-
raise ValueError('Illegal app name argument type: "{}". App name '
132-
'must be a string.'.format(type(name)))
130+
raise ValueError(
131+
f'Illegal app name argument type: "{type(name)}". App name must be a string.')
133132
with _apps_lock:
134133
if name in _apps:
135134
return _apps[name]
@@ -140,9 +139,9 @@ def get_app(name=_DEFAULT_APP_NAME):
140139
'the SDK by calling initialize_app().')
141140

142141
raise ValueError(
143-
('Firebase app named "{0}" does not exist. Make sure to initialize '
144-
'the SDK by calling initialize_app() with your app name as the '
145-
'second argument.').format(name))
142+
f'Firebase app named "{name}" does not exist. Make sure to initialize '
143+
'the SDK by calling initialize_app() with your app name as the '
144+
'second argument.')
146145

147146

148147
class _AppOptions:
@@ -153,8 +152,9 @@ def __init__(self, options):
153152
options = self._load_from_environment()
154153

155154
if not isinstance(options, dict):
156-
raise ValueError('Illegal Firebase app options type: {0}. Options '
157-
'must be a dictionary.'.format(type(options)))
155+
raise ValueError(
156+
f'Illegal Firebase app options type: {type(options)}. '
157+
'Options must be a dictionary.')
158158
self._options = options
159159

160160
def get(self, key, default=None):
@@ -175,15 +175,15 @@ def _load_from_environment(self):
175175
json_str = config_file
176176
else:
177177
try:
178-
with open(config_file, 'r') as json_file:
178+
with open(config_file, 'r', encoding='utf-8') as json_file:
179179
json_str = json_file.read()
180180
except Exception as err:
181-
raise ValueError('Unable to read file {}. {}'.format(config_file, err)) from err
181+
raise ValueError(f'Unable to read file {config_file}. {err}') from err
182182
try:
183183
json_data = json.loads(json_str)
184184
except Exception as err:
185185
raise ValueError(
186-
'JSON string "{0}" is not valid json. {1}'.format(json_str, err)) from err
186+
f'JSON string "{json_str}" is not valid json. {err}') from err
187187
return {k: v for k, v in json_data.items() if k in _CONFIG_VALID_KEYS}
188188

189189

@@ -206,8 +206,9 @@ def __init__(self, name, credential, options):
206206
ValueError: If an argument is None or invalid.
207207
"""
208208
if not name or not isinstance(name, str):
209-
raise ValueError('Illegal Firebase app name "{0}" provided. App name must be a '
210-
'non-empty string.'.format(name))
209+
raise ValueError(
210+
f'Illegal Firebase app name "{name}" provided. App name must be a '
211+
'non-empty string.')
211212
self._name = name
212213

213214
if isinstance(credential, GoogleAuthCredentials):
@@ -228,7 +229,7 @@ def __init__(self, name, credential, options):
228229
def _validate_project_id(cls, project_id):
229230
if project_id is not None and not isinstance(project_id, str):
230231
raise ValueError(
231-
'Invalid project ID: "{0}". project ID must be a string.'.format(project_id))
232+
f'Invalid project ID: "{project_id}". project ID must be a string.')
232233

233234
@property
234235
def name(self):
@@ -293,11 +294,11 @@ def _get_service(self, name, initializer):
293294
"""
294295
if not name or not isinstance(name, str):
295296
raise ValueError(
296-
'Illegal name argument: "{0}". Name must be a non-empty string.'.format(name))
297+
f'Illegal name argument: "{name}". Name must be a non-empty string.')
297298
with self._lock:
298299
if self._services is None:
299300
raise ValueError(
300-
'Service requested from deleted Firebase App: "{0}".'.format(self._name))
301+
f'Service requested from deleted Firebase App: "{self._name}".')
301302
if name not in self._services:
302303
self._services[name] = initializer(self)
303304
return self._services[name]

firebase_admin/_auth_client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, app, tenant_id=None):
3838
3. set the project ID via the GOOGLE_CLOUD_PROJECT environment variable.""")
3939

4040
credential = None
41-
version_header = 'Python/Admin/{0}'.format(firebase_admin.__version__)
41+
version_header = f'Python/Admin/{firebase_admin.__version__}'
4242
timeout = app.options.get('httpTimeout', _http_client.DEFAULT_TIMEOUT_SECONDS)
4343
# Non-default endpoint URLs for emulator support are set in this dict later.
4444
endpoint_urls = {}
@@ -48,7 +48,7 @@ def __init__(self, app, tenant_id=None):
4848
# endpoint URLs to use the emulator. Additionally, use a fake credential.
4949
emulator_host = _auth_utils.get_emulator_host()
5050
if emulator_host:
51-
base_url = 'http://{0}/identitytoolkit.googleapis.com'.format(emulator_host)
51+
base_url = f'http://{emulator_host}/identitytoolkit.googleapis.com'
5252
endpoint_urls['v1'] = base_url + '/v1'
5353
endpoint_urls['v2'] = base_url + '/v2'
5454
credential = _utils.EmulatorAdminCredentials()
@@ -123,15 +123,16 @@ def verify_id_token(self, id_token, check_revoked=False, clock_skew_seconds=0):
123123
"""
124124
if not isinstance(check_revoked, bool):
125125
# guard against accidental wrong assignment.
126-
raise ValueError('Illegal check_revoked argument. Argument must be of type '
127-
' bool, but given "{0}".'.format(type(check_revoked)))
126+
raise ValueError(
127+
'Illegal check_revoked argument. Argument must be of type bool, but given '
128+
f'"{type(check_revoked)}".')
128129

129130
verified_claims = self._token_verifier.verify_id_token(id_token, clock_skew_seconds)
130131
if self.tenant_id:
131132
token_tenant_id = verified_claims.get('firebase', {}).get('tenant')
132133
if self.tenant_id != token_tenant_id:
133134
raise _auth_utils.TenantIdMismatchError(
134-
'Invalid tenant ID: {0}'.format(token_tenant_id))
135+
f'Invalid tenant ID: {token_tenant_id}')
135136

136137
if check_revoked:
137138
self._check_jwt_revoked_or_disabled(
@@ -249,7 +250,7 @@ def _matches(identifier, user_record):
249250
if identifier.provider_id == user_info.provider_id
250251
and identifier.provider_uid == user_info.uid
251252
), False)
252-
raise TypeError("Unexpected type: {}".format(type(identifier)))
253+
raise TypeError(f"Unexpected type: {type(identifier)}")
253254

254255
def _is_user_found(identifier, user_records):
255256
return any(_matches(identifier, user_record) for user_record in user_records)
@@ -757,4 +758,4 @@ def _check_jwt_revoked_or_disabled(self, verified_claims, exc_type, label):
757758
if user.disabled:
758759
raise _auth_utils.UserDisabledError('The user record is disabled.')
759760
if verified_claims.get('iat') * 1000 < user.tokens_valid_after_timestamp:
760-
raise exc_type('The Firebase {0} has been revoked.'.format(label))
761+
raise exc_type(f'The Firebase {label} has been revoked.')

firebase_admin/_auth_providers.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ class ProviderConfigClient:
181181
def __init__(self, http_client, project_id, tenant_id=None, url_override=None):
182182
self.http_client = http_client
183183
url_prefix = url_override or self.PROVIDER_CONFIG_URL
184-
self.base_url = '{0}/projects/{1}'.format(url_prefix, project_id)
184+
self.base_url = f'{url_prefix}/projects/{project_id}'
185185
if tenant_id:
186-
self.base_url += '/tenants/{0}'.format(tenant_id)
186+
self.base_url += f'/tenants/{tenant_id}'
187187

188188
def get_oidc_provider_config(self, provider_id):
189189
_validate_oidc_provider_id(provider_id)
190-
body = self._make_request('get', '/oauthIdpConfigs/{0}'.format(provider_id))
190+
body = self._make_request('get', f'/oauthIdpConfigs/{provider_id}')
191191
return OIDCProviderConfig(body)
192192

193193
def create_oidc_provider_config(
@@ -218,7 +218,7 @@ def create_oidc_provider_config(
218218
if response_type:
219219
req['responseType'] = response_type
220220

221-
params = 'oauthIdpConfigId={0}'.format(provider_id)
221+
params = f'oauthIdpConfigId={provider_id}'
222222
body = self._make_request('post', '/oauthIdpConfigs', json=req, params=params)
223223
return OIDCProviderConfig(body)
224224

@@ -259,14 +259,14 @@ def update_oidc_provider_config(
259259
raise ValueError('At least one parameter must be specified for update.')
260260

261261
update_mask = _auth_utils.build_update_mask(req)
262-
params = 'updateMask={0}'.format(','.join(update_mask))
263-
url = '/oauthIdpConfigs/{0}'.format(provider_id)
262+
params = f'updateMask={",".join(update_mask)}'
263+
url = f'/oauthIdpConfigs/{provider_id}'
264264
body = self._make_request('patch', url, json=req, params=params)
265265
return OIDCProviderConfig(body)
266266

267267
def delete_oidc_provider_config(self, provider_id):
268268
_validate_oidc_provider_id(provider_id)
269-
self._make_request('delete', '/oauthIdpConfigs/{0}'.format(provider_id))
269+
self._make_request('delete', f'/oauthIdpConfigs/{provider_id}')
270270

271271
def list_oidc_provider_configs(self, page_token=None, max_results=MAX_LIST_CONFIGS_RESULTS):
272272
return _ListOIDCProviderConfigsPage(
@@ -277,7 +277,7 @@ def _fetch_oidc_provider_configs(self, page_token=None, max_results=MAX_LIST_CON
277277

278278
def get_saml_provider_config(self, provider_id):
279279
_validate_saml_provider_id(provider_id)
280-
body = self._make_request('get', '/inboundSamlConfigs/{0}'.format(provider_id))
280+
body = self._make_request('get', f'/inboundSamlConfigs/{provider_id}')
281281
return SAMLProviderConfig(body)
282282

283283
def create_saml_provider_config(
@@ -301,7 +301,7 @@ def create_saml_provider_config(
301301
if enabled is not None:
302302
req['enabled'] = _auth_utils.validate_boolean(enabled, 'enabled')
303303

304-
params = 'inboundSamlConfigId={0}'.format(provider_id)
304+
params = f'inboundSamlConfigId={provider_id}'
305305
body = self._make_request('post', '/inboundSamlConfigs', json=req, params=params)
306306
return SAMLProviderConfig(body)
307307

@@ -341,14 +341,14 @@ def update_saml_provider_config(
341341
raise ValueError('At least one parameter must be specified for update.')
342342

343343
update_mask = _auth_utils.build_update_mask(req)
344-
params = 'updateMask={0}'.format(','.join(update_mask))
345-
url = '/inboundSamlConfigs/{0}'.format(provider_id)
344+
params = f'updateMask={",".join(update_mask)}'
345+
url = f'/inboundSamlConfigs/{provider_id}'
346346
body = self._make_request('patch', url, json=req, params=params)
347347
return SAMLProviderConfig(body)
348348

349349
def delete_saml_provider_config(self, provider_id):
350350
_validate_saml_provider_id(provider_id)
351-
self._make_request('delete', '/inboundSamlConfigs/{0}'.format(provider_id))
351+
self._make_request('delete', f'/inboundSamlConfigs/{provider_id}')
352352

353353
def list_saml_provider_configs(self, page_token=None, max_results=MAX_LIST_CONFIGS_RESULTS):
354354
return _ListSAMLProviderConfigsPage(
@@ -367,15 +367,15 @@ def _fetch_provider_configs(self, path, page_token=None, max_results=MAX_LIST_CO
367367
if max_results < 1 or max_results > MAX_LIST_CONFIGS_RESULTS:
368368
raise ValueError(
369369
'Max results must be a positive integer less than or equal to '
370-
'{0}.'.format(MAX_LIST_CONFIGS_RESULTS))
370+
f'{MAX_LIST_CONFIGS_RESULTS}.')
371371

372-
params = 'pageSize={0}'.format(max_results)
372+
params = f'pageSize={max_results}'
373373
if page_token:
374-
params += '&pageToken={0}'.format(page_token)
374+
params += f'&pageToken={page_token}'
375375
return self._make_request('get', path, params=params)
376376

377377
def _make_request(self, method, path, **kwargs):
378-
url = '{0}{1}'.format(self.base_url, path)
378+
url = f'{self.base_url}{path}'
379379
try:
380380
return self.http_client.body(method, url, **kwargs)
381381
except requests.exceptions.RequestException as error:
@@ -385,45 +385,42 @@ def _make_request(self, method, path, **kwargs):
385385
def _validate_oidc_provider_id(provider_id):
386386
if not isinstance(provider_id, str):
387387
raise ValueError(
388-
'Invalid OIDC provider ID: {0}. Provider ID must be a non-empty string.'.format(
389-
provider_id))
388+
f'Invalid OIDC provider ID: {provider_id}. Provider ID must be a non-empty string.')
390389
if not provider_id.startswith('oidc.'):
391-
raise ValueError('Invalid OIDC provider ID: {0}.'.format(provider_id))
390+
raise ValueError(f'Invalid OIDC provider ID: {provider_id}.')
392391
return provider_id
393392

394393

395394
def _validate_saml_provider_id(provider_id):
396395
if not isinstance(provider_id, str):
397396
raise ValueError(
398-
'Invalid SAML provider ID: {0}. Provider ID must be a non-empty string.'.format(
399-
provider_id))
397+
f'Invalid SAML provider ID: {provider_id}. Provider ID must be a non-empty string.')
400398
if not provider_id.startswith('saml.'):
401-
raise ValueError('Invalid SAML provider ID: {0}.'.format(provider_id))
399+
raise ValueError(f'Invalid SAML provider ID: {provider_id}.')
402400
return provider_id
403401

404402

405403
def _validate_non_empty_string(value, label):
406404
"""Validates that the given value is a non-empty string."""
407405
if not isinstance(value, str):
408-
raise ValueError('Invalid type for {0}: {1}.'.format(label, value))
406+
raise ValueError(f'Invalid type for {label}: {value}.')
409407
if not value:
410-
raise ValueError('{0} must not be empty.'.format(label))
408+
raise ValueError(f'{label} must not be empty.')
411409
return value
412410

413411

414412
def _validate_url(url, label):
415413
"""Validates that the given value is a well-formed URL string."""
416414
if not isinstance(url, str) or not url:
417415
raise ValueError(
418-
'Invalid photo URL: "{0}". {1} must be a non-empty '
419-
'string.'.format(url, label))
416+
f'Invalid photo URL: "{url}". {label} must be a non-empty string.')
420417
try:
421418
parsed = parse.urlparse(url)
422419
if not parsed.netloc:
423-
raise ValueError('Malformed {0}: "{1}".'.format(label, url))
420+
raise ValueError(f'Malformed {label}: "{url}".')
424421
return url
425422
except Exception as exception:
426-
raise ValueError('Malformed {0}: "{1}".'.format(label, url)) from exception
423+
raise ValueError(f'Malformed {label}: "{url}".') from exception
427424

428425

429426
def _validate_x509_certificates(x509_certificates):

0 commit comments

Comments
 (0)