Skip to content

Commit 255c670

Browse files
authored
refactor: convert formatted strings to f-strings (#272)
1 parent 70efe6d commit 255c670

38 files changed

Lines changed: 91 additions & 91 deletions

alertaclient/api.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,22 @@ def alert_note(self, id, text):
150150
data = {
151151
'text': text
152152
}
153-
r = self.http.put('/alert/{}/note'.format(id), data)
153+
r = self.http.put(f'/alert/{id}/note', data)
154154
return Note.parse(r['note'])
155155

156156
def get_alert_notes(self, id, page=1, page_size=None):
157-
r = self.http.get('/alert/{}/notes'.format(id), page=page, page_size=page_size)
157+
r = self.http.get(f'/alert/{id}/notes', page=page, page_size=page_size)
158158
return [Note.parse(n) for n in r['notes']]
159159

160160
def update_alert_note(self, id, note_id, text):
161161
data = {
162162
'text': text,
163163
}
164-
r = self.http.put('/alert/{}/note/{}'.format(id, note_id), data)
164+
r = self.http.put(f'/alert/{id}/note/{note_id}', data)
165165
return Note.parse(r['note'])
166166

167167
def delete_alert_note(self, id, note_id):
168-
return self.http.delete('/alert/{}/note/{}'.format(id, note_id))
168+
return self.http.delete(f'/alert/{id}/note/{note_id}')
169169

170170
# Blackouts
171171
def create_blackout(self, environment, service=None, resource=None, event=None, group=None, tags=None,
@@ -208,7 +208,7 @@ def update_blackout(self, id, **kwargs):
208208
'text': kwargs.get('text'),
209209
}
210210

211-
r = self.http.put('/blackout/{}'.format(id), data)
211+
r = self.http.put(f'/blackout/{id}', data)
212212
return Blackout.parse(r['blackout'])
213213

214214
def delete_blackout(self, id):
@@ -235,7 +235,7 @@ def update_customer(self, id, **kwargs):
235235
'match': kwargs.get('match'),
236236
'customer': kwargs.get('customer')
237237
}
238-
r = self.http.put('/customer/{}'.format(id), data)
238+
r = self.http.put(f'/customer/{id}', data)
239239
return Customer.parse(r['customer'])
240240

241241
def delete_customer(self, id):
@@ -292,7 +292,7 @@ def update_key(self, id, **kwargs):
292292
'expireTime': kwargs.get('expireTime'),
293293
'customer': kwargs.get('customer')
294294
}
295-
r = self.http.put('/key/{}'.format(id), data)
295+
r = self.http.put(f'/key/{id}', data)
296296
return ApiKey.parse(r['key'])
297297

298298
def delete_key(self, id):
@@ -319,7 +319,7 @@ def update_perm(self, id, **kwargs):
319319
'match': kwargs.get('match'), # role
320320
'scopes': kwargs.get('scopes')
321321
}
322-
r = self.http.put('/perm/{}'.format(id), data)
322+
r = self.http.put(f'/perm/{id}', data)
323323
return Permission.parse(r['permission'])
324324

325325
def delete_perm(self, id):
@@ -359,7 +359,7 @@ def get_user(self, id):
359359
return User.parse(self.http.get('/user/%s' % id)['user'])
360360

361361
def get_user_groups(self, id):
362-
r = self.http.get('/user/{}/groups'.format(id))
362+
r = self.http.get(f'/user/{id}/groups')
363363
return [Group.parse(g) for g in r['groups']]
364364

365365
def get_me(self):
@@ -383,7 +383,7 @@ def update_user(self, id, **kwargs):
383383
'text': kwargs.get('text'),
384384
'email_verified': kwargs.get('email_verified')
385385
}
386-
r = self.http.put('/user/{}'.format(id), data)
386+
r = self.http.put(f'/user/{id}', data)
387387
return User.parse(r['user'])
388388

389389
def update_me(self, **kwargs):
@@ -452,7 +452,7 @@ def get_group(self):
452452
return Group.parse(self.http.get('/group/%s' % id)['group'])
453453

454454
def get_group_users(self, id):
455-
r = self.http.get('/group/{}/users'.format(id))
455+
r = self.http.get(f'/group/{id}/users')
456456
return [User.parse(u) for u in r['users']]
457457

458458
def get_users_groups(self, query=None):
@@ -464,14 +464,14 @@ def update_group(self, id, **kwargs):
464464
'name': kwargs.get('name'),
465465
'text': kwargs.get('text')
466466
}
467-
r = self.http.put('/group/{}'.format(id), data)
467+
r = self.http.put(f'/group/{id}', data)
468468
return Group.parse(r['group'])
469469

470470
def add_user_to_group(self, group_id, user_id):
471-
return self.http.put('/group/{}/user/{}'.format(group_id, user_id))
471+
return self.http.put(f'/group/{group_id}/user/{user_id}')
472472

473473
def remove_user_from_group(self, group_id, user_id):
474-
return self.http.delete('/group/{}/user/{}'.format(group_id, user_id))
474+
return self.http.delete(f'/group/{group_id}/user/{user_id}')
475475

476476
def delete_group(self, id):
477477
return self.http.delete('/group/%s' % id)
@@ -500,7 +500,7 @@ def __init__(self, api_key=None, auth_token=None):
500500
self.auth_token = auth_token
501501

502502
def __call__(self, r):
503-
r.headers['Authorization'] = 'Key {}'.format(self.api_key)
503+
r.headers['Authorization'] = f'Key {self.api_key}'
504504
return r
505505

506506

@@ -510,7 +510,7 @@ def __init__(self, auth_token=None):
510510
self.auth_token = auth_token
511511

512512
def __call__(self, r):
513-
r.headers['Authorization'] = 'Bearer {}'.format(self.auth_token)
513+
r.headers['Authorization'] = f'Bearer {self.auth_token}'
514514
return r
515515

516516

@@ -608,7 +608,7 @@ def delete(self, path):
608608

609609
def _handle_error(self, response):
610610
if self.debug:
611-
print('\nbody: {}'.format(response.text))
611+
print(f'\nbody: {response.text}')
612612
resp = response.json()
613613
status = resp.get('status', None)
614614
if status == 'ok':

alertaclient/auth/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def save_token(endpoint, username, token):
2929
try:
3030
info = netrc(NETRC_FILE)
3131
except Exception as e:
32-
raise ConfigurationError('{}'.format(e))
32+
raise ConfigurationError(f'{e}')
3333
info.hosts[machine(endpoint)] = (username, None, token)
3434
with open(NETRC_FILE, 'w') as f:
3535
f.write(dump_netrc(info))
@@ -39,13 +39,13 @@ def clear_token(endpoint):
3939
try:
4040
info = netrc(NETRC_FILE)
4141
except Exception as e:
42-
raise ConfigurationError('{}'.format(e))
42+
raise ConfigurationError(f'{e}')
4343
try:
4444
del info.hosts[machine(endpoint)]
4545
with open(NETRC_FILE, 'w') as f:
4646
f.write(dump_netrc(info))
4747
except KeyError as e:
48-
raise ConfigurationError('No credentials stored for {}'.format(e))
48+
raise ConfigurationError(f'No credentials stored for {e}')
4949

5050

5151
# See https://bugs.python.org/issue30806

alertaclient/commands/cmd_ack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text):
2222
total, _, _ = client.get_count(query)
2323
ids = [a.id for a in client.get_alerts(query)]
2424

25-
action_progressbar(client, action='ack', ids=ids, label='Acking {} alerts'.format(total), text=text)
25+
action_progressbar(client, action='ack', ids=ids, label=f'Acking {total} alerts', text=text)

alertaclient/commands/cmd_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ def cli(obj, action, ids, query, filters, text):
2323
total, _, _ = client.get_count(query)
2424
ids = [a.id for a in client.get_alerts(query)]
2525

26-
label = 'Action ({}) {} alerts'.format(action, total)
26+
label = f'Action ({action}) {total} alerts'
2727
action_progressbar(client, action=action, ids=ids, label=label, text=text)

alertaclient/commands/cmd_blackout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ def cli(obj, environment, service, resource, event, group, tags, origin, custome
4040
text=text
4141
)
4242
except Exception as e:
43-
click.echo('ERROR: {}'.format(e), err=True)
43+
click.echo(f'ERROR: {e}', err=True)
4444
sys.exit(1)
4545
click.echo(blackout.id)

alertaclient/commands/cmd_blackouts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ def cli(obj, purge):
2727

2828
expired = [b for b in blackouts if b.status == 'expired']
2929
if purge:
30-
with click.progressbar(expired, label='Purging {} blackouts'.format(len(expired))) as bar:
30+
with click.progressbar(expired, label=f'Purging {len(expired)} blackouts') as bar:
3131
for b in bar:
3232
client.delete_blackout(b.id)

alertaclient/commands/cmd_close.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text):
2222
total, _, _ = client.get_count(query)
2323
ids = [a.id for a in client.get_alerts(query)]
2424

25-
action_progressbar(client, action='close', ids=ids, label='Closing {} alerts'.format(total), text=text)
25+
action_progressbar(client, action='close', ids=ids, label=f'Closing {total} alerts', text=text)

alertaclient/commands/cmd_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ def cli(obj):
88
for k, v in obj.items():
99
if isinstance(v, list):
1010
v = ', '.join(v)
11-
click.echo('{:20}: {}'.format(k, v))
11+
click.echo(f'{k:20}: {v}')

alertaclient/commands/cmd_customer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def cli(obj, customer, match, delete):
2121
try:
2222
customer = client.create_customer(customer, match)
2323
except Exception as e:
24-
click.echo('ERROR: {}'.format(e), err=True)
24+
click.echo(f'ERROR: {e}', err=True)
2525
sys.exit(1)
2626
click.echo(customer.id)

alertaclient/commands/cmd_delete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ def cli(obj, ids, query, filters):
2323
total, _, _ = client.get_count(query)
2424
ids = [a.id for a in client.get_alerts(query)]
2525

26-
with click.progressbar(ids, label='Deleting {} alerts'.format(total)) as bar:
26+
with click.progressbar(ids, label=f'Deleting {total} alerts') as bar:
2727
for id in bar:
2828
client.delete_alert(id)

0 commit comments

Comments
 (0)