aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2022-12-02 23:55:32 +0200
committerGitHub <[email protected]>2022-12-02 23:55:32 +0200
commitf5d4fbc1f0bd61e80f9daced15d7ef7ee349b50f (patch)
tree247b41199512db9693d00baf7522602805e31c3f /mastodon
parentc796cf39b01e38fe381fb4743988da991b072183 (diff)
parent325cc917d5ad14b130b156d23b7adca46499dc24 (diff)
downloadmastodon.py-f5d4fbc1f0bd61e80f9daced15d7ef7ee349b50f.tar.gz
Merge pull request #290 from eumiro/fstrings
refactor: use f-strings
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/accounts.py59
-rw-r--r--mastodon/admin.py35
-rw-r--r--mastodon/authentication.py12
-rw-r--r--mastodon/conversations.py3
-rw-r--r--mastodon/filters.py9
-rw-r--r--mastodon/hashtags.py4
-rw-r--r--mastodon/instance.py11
-rw-r--r--mastodon/internals.py40
-rw-r--r--mastodon/lists.py14
-rw-r--r--mastodon/media.py10
-rw-r--r--mastodon/notifications.py6
-rw-r--r--mastodon/polls.py8
-rw-r--r--mastodon/relationships.py6
-rw-r--r--mastodon/statuses.py72
-rw-r--r--mastodon/streaming_endpoints.py4
-rw-r--r--mastodon/suggestions.py3
-rw-r--r--mastodon/timeline.py7
-rw-r--r--mastodon/utility.py13
18 files changed, 129 insertions, 187 deletions
diff --git a/mastodon/accounts.py b/mastodon/accounts.py
index 219edac..3d10088 100644
--- a/mastodon/accounts.py
+++ b/mastodon/accounts.py
@@ -66,7 +66,7 @@ class Mastodon(Internals):
66 response = self.__api_request('POST', '/oauth/token', oauth_params, do_ratelimiting=False) 66 response = self.__api_request('POST', '/oauth/token', oauth_params, do_ratelimiting=False)
67 temp_access_token = response['access_token'] 67 temp_access_token = response['access_token']
68 except Exception as e: 68 except Exception as e:
69 raise MastodonIllegalArgumentError('Invalid request during oauth phase: %s' % e) 69 raise MastodonIllegalArgumentError(f'Invalid request during oauth phase: {e}')
70 70
71 # Step 2: Use that to create a user 71 # Step 2: Use that to create a user
72 try: 72 try:
@@ -74,7 +74,7 @@ class Mastodon(Internals):
74 if "error" in response: 74 if "error" in response:
75 if return_detailed_error: 75 if return_detailed_error:
76 return None, response 76 return None, response
77 raise MastodonIllegalArgumentError('Invalid request: %s' % e) 77 raise MastodonIllegalArgumentError(f'Invalid request: {e}')
78 self.access_token = response['access_token'] 78 self.access_token = response['access_token']
79 self.__set_refresh_token(response.get('refresh_token')) 79 self.__set_refresh_token(response.get('refresh_token'))
80 self.__set_token_expired(int(response.get('expires_in', 0))) 80 self.__set_token_expired(int(response.get('expires_in', 0)))
@@ -88,7 +88,10 @@ class Mastodon(Internals):
88 received_scopes += _SCOPE_SETS[scope_set] 88 received_scopes += _SCOPE_SETS[scope_set]
89 89
90 if not set(scopes) <= set(received_scopes): 90 if not set(scopes) <= set(received_scopes):
91 raise MastodonAPIError('Granted scopes "' + " ".join(received_scopes) + '" do not contain all of the requested scopes "' + " ".join(scopes) + '".') 91 raise MastodonAPIError(
92 f'Granted scopes "{" ".join(received_scopes)}" '
93 f'do not contain all of the requested scopes "{" ".join(scopes)}".'
94 )
92 95
93 if to_file is not None: 96 if to_file is not None:
94 with open(to_file, 'w') as token_file: 97 with open(to_file, 'w') as token_file:
@@ -124,8 +127,7 @@ class Mastodon(Internals):
124 Returns a :ref:`account dict <account dict>`. 127 Returns a :ref:`account dict <account dict>`.
125 """ 128 """
126 id = self.__unpack_id(id) 129 id = self.__unpack_id(id)
127 url = '/api/v1/accounts/{0}'.format(str(id)) 130 return self.__api_request('GET', f'/api/v1/accounts/{id}')
128 return self.__api_request('GET', url)
129 131
130 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) 132 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
131 def account_verify_credentials(self): 133 def account_verify_credentials(self):
@@ -185,8 +187,7 @@ class Mastodon(Internals):
185 if not exclude_reblogs: 187 if not exclude_reblogs:
186 del params["exclude_reblogs"] 188 del params["exclude_reblogs"]
187 189
188 url = '/api/v1/accounts/{0}/statuses'.format(str(id)) 190 return self.__api_request('GET', f'/api/v1/accounts/{id}/statuses', params)
189 return self.__api_request('GET', url, params)
190 191
191 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT) 192 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
192 def account_following(self, id, max_id=None, min_id=None, since_id=None, limit=None): 193 def account_following(self, id, max_id=None, min_id=None, since_id=None, limit=None):
@@ -206,8 +207,7 @@ class Mastodon(Internals):
206 since_id = self.__unpack_id(since_id, dateconv=True) 207 since_id = self.__unpack_id(since_id, dateconv=True)
207 208
208 params = self.__generate_params(locals(), ['id']) 209 params = self.__generate_params(locals(), ['id'])
209 url = '/api/v1/accounts/{0}/following'.format(str(id)) 210 return self.__api_request('GET', f'/api/v1/accounts/{id}/following', params)
210 return self.__api_request('GET', url, params)
211 211
212 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT) 212 @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT)
213 def account_followers(self, id, max_id=None, min_id=None, since_id=None, limit=None): 213 def account_followers(self, id, max_id=None, min_id=None, since_id=None, limit=None):
@@ -227,8 +227,7 @@ class Mastodon(Internals):
227 since_id = self.__unpack_id(since_id, dateconv=True) 227 since_id = self.__unpack_id(since_id, dateconv=True)
228 228
229 params = self.__generate_params(locals(), ['id']) 229 params = self.__generate_params(locals(), ['id'])
230 url = '/api/v1/accounts/{0}/followers'.format(str(id)) 230 return self.__api_request('GET', f'/api/v1/accounts/{id}/followers', params)
231 return self.__api_request('GET', url, params)
232 231
233 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 232 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
234 def account_relationships(self, id): 233 def account_relationships(self, id):
@@ -269,8 +268,7 @@ class Mastodon(Internals):
269 """ 268 """
270 id = self.__unpack_id(id) 269 id = self.__unpack_id(id)
271 params = self.__generate_params(locals(), ['id']) 270 params = self.__generate_params(locals(), ['id'])
272 url = '/api/v1/accounts/{0}/lists'.format(str(id)) 271 return self.__api_request('GET', f'/api/v1/accounts/{id}/lists', params)
273 return self.__api_request('GET', url, params)
274 272
275 @api_version("3.4.0", "3.4.0", _DICT_VERSION_ACCOUNT) 273 @api_version("3.4.0", "3.4.0", _DICT_VERSION_ACCOUNT)
276 def account_lookup(self, acct): 274 def account_lookup(self, acct):
@@ -317,8 +315,7 @@ class Mastodon(Internals):
317 if params["reblogs"] is None: 315 if params["reblogs"] is None:
318 del params["reblogs"] 316 del params["reblogs"]
319 317
320 url = '/api/v1/accounts/{0}/follow'.format(str(id)) 318 return self.__api_request('POST', f'/api/v1/accounts/{id}/follow', params)
321 return self.__api_request('POST', url, params)
322 319
323 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) 320 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
324 def follows(self, uri): 321 def follows(self, uri):
@@ -338,7 +335,7 @@ class Mastodon(Internals):
338 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 335 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
339 """ 336 """
340 id = self.__unpack_id(id) 337 id = self.__unpack_id(id)
341 return self.__api_request('POST', '/api/v1/accounts/{0}/unfollow'.format(str(id))) 338 return self.__api_request('POST', f'/api/v1/accounts/{id}/unfollow')
342 339
343 @api_version("3.5.0", "3.5.0", _DICT_VERSION_RELATIONSHIP) 340 @api_version("3.5.0", "3.5.0", _DICT_VERSION_RELATIONSHIP)
344 def account_remove_from_followers(self, id): 341 def account_remove_from_followers(self, id):
@@ -349,7 +346,7 @@ class Mastodon(Internals):
349 Returns a :ref:`relationship dict <relationship dict>` reflecting the updated following status. 346 Returns a :ref:`relationship dict <relationship dict>` reflecting the updated following status.
350 """ 347 """
351 id = self.__unpack_id(id) 348 id = self.__unpack_id(id)
352 return self.__api_request('POST', '/api/v1/accounts/{0}/remove_from_followers'.format(str(id))) 349 return self.__api_request('POST', f'/api/v1/accounts/{id}/remove_from_followers')
353 350
354 351
355 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 352 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
@@ -360,8 +357,7 @@ class Mastodon(Internals):
360 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 357 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
361 """ 358 """
362 id = self.__unpack_id(id) 359 id = self.__unpack_id(id)
363 url = '/api/v1/accounts/{0}/block'.format(str(id)) 360 return self.__api_request('POST', f'/api/v1/accounts/{id}/block')
364 return self.__api_request('POST', url)
365 361
366 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 362 @api_version("1.0.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
367 def account_unblock(self, id): 363 def account_unblock(self, id):
@@ -371,8 +367,7 @@ class Mastodon(Internals):
371 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 367 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
372 """ 368 """
373 id = self.__unpack_id(id) 369 id = self.__unpack_id(id)
374 url = '/api/v1/accounts/{0}/unblock'.format(str(id)) 370 return self.__api_request('POST', f'/api/v1/accounts/{id}/unblock')
375 return self.__api_request('POST', url)
376 371
377 @api_version("1.1.0", "2.4.3", _DICT_VERSION_RELATIONSHIP) 372 @api_version("1.1.0", "2.4.3", _DICT_VERSION_RELATIONSHIP)
378 def account_mute(self, id, notifications=True, duration=None): 373 def account_mute(self, id, notifications=True, duration=None):
@@ -387,8 +382,7 @@ class Mastodon(Internals):
387 """ 382 """
388 id = self.__unpack_id(id) 383 id = self.__unpack_id(id)
389 params = self.__generate_params(locals(), ['id']) 384 params = self.__generate_params(locals(), ['id'])
390 url = '/api/v1/accounts/{0}/mute'.format(str(id)) 385 return self.__api_request('POST', f'/api/v1/accounts/{id}/mute', params)
391 return self.__api_request('POST', url, params)
392 386
393 @api_version("1.1.0", "1.4.0", _DICT_VERSION_RELATIONSHIP) 387 @api_version("1.1.0", "1.4.0", _DICT_VERSION_RELATIONSHIP)
394 def account_unmute(self, id): 388 def account_unmute(self, id):
@@ -398,8 +392,7 @@ class Mastodon(Internals):
398 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 392 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
399 """ 393 """
400 id = self.__unpack_id(id) 394 id = self.__unpack_id(id)
401 url = '/api/v1/accounts/{0}/unmute'.format(str(id)) 395 return self.__api_request('POST', f'/api/v1/accounts/{id}/unmute', params)
402 return self.__api_request('POST', url)
403 396
404 @api_version("1.1.1", "3.1.0", _DICT_VERSION_ACCOUNT) 397 @api_version("1.1.1", "3.1.0", _DICT_VERSION_ACCOUNT)
405 def account_update_credentials(self, display_name=None, note=None, 398 def account_update_credentials(self, display_name=None, note=None,
@@ -436,10 +429,8 @@ class Mastodon(Internals):
436 429
437 fields_attributes = [] 430 fields_attributes = []
438 for idx, (field_name, field_value) in enumerate(fields): 431 for idx, (field_name, field_value) in enumerate(fields):
439 params_initial['fields_attributes[' + 432 params_initial[f'fields_attributes[{idx}][name]'] = field_name
440 str(idx) + '][name]'] = field_name 433 params_initial[f'fields_attributes[{idx}][value]'] = field_value
441 params_initial['fields_attributes[' +
442 str(idx) + '][value]'] = field_value
443 434
444 # Clean up params 435 # Clean up params
445 for param in ["avatar", "avatar_mime_type", "header", "header_mime_type", "fields"]: 436 for param in ["avatar", "avatar_mime_type", "header", "header_mime_type", "fields"]:
@@ -464,8 +455,7 @@ class Mastodon(Internals):
464 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 455 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
465 """ 456 """
466 id = self.__unpack_id(id) 457 id = self.__unpack_id(id)
467 url = '/api/v1/accounts/{0}/pin'.format(str(id)) 458 return self.__api_request('POST', f'/api/v1/accounts/{id}/pin')
468 return self.__api_request('POST', url)
469 459
470 @api_version("2.5.0", "2.5.0", _DICT_VERSION_RELATIONSHIP) 460 @api_version("2.5.0", "2.5.0", _DICT_VERSION_RELATIONSHIP)
471 def account_unpin(self, id): 461 def account_unpin(self, id):
@@ -475,8 +465,7 @@ class Mastodon(Internals):
475 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user. 465 Returns a :ref:`relationship dict <relationship dict>` containing the updated relationship to the user.
476 """ 466 """
477 id = self.__unpack_id(id) 467 id = self.__unpack_id(id)
478 url = '/api/v1/accounts/{0}/unpin'.format(str(id)) 468 return self.__api_request('POST', f'/api/v1/accounts/{id}/unpin')
479 return self.__api_request('POST', url)
480 469
481 @api_version("3.2.0", "3.2.0", _DICT_VERSION_RELATIONSHIP) 470 @api_version("3.2.0", "3.2.0", _DICT_VERSION_RELATIONSHIP)
482 def account_note_set(self, id, comment): 471 def account_note_set(self, id, comment):
@@ -487,7 +476,7 @@ class Mastodon(Internals):
487 """ 476 """
488 id = self.__unpack_id(id) 477 id = self.__unpack_id(id)
489 params = self.__generate_params(locals(), ["id"]) 478 params = self.__generate_params(locals(), ["id"])
490 return self.__api_request('POST', '/api/v1/accounts/{0}/note'.format(str(id)), params) 479 return self.__api_request('POST', f'/api/v1/accounts/{id}/note', params)
491 480
492 @api_version("3.3.0", "3.3.0", _DICT_VERSION_HASHTAG) 481 @api_version("3.3.0", "3.3.0", _DICT_VERSION_HASHTAG)
493 def account_featured_tags(self, id): 482 def account_featured_tags(self, id):
@@ -497,4 +486,4 @@ class Mastodon(Internals):
497 Returns a list of :ref:`hashtag dicts <hashtag dicts>` (NOT `featured tag dicts`_). 486 Returns a list of :ref:`hashtag dicts <hashtag dicts>` (NOT `featured tag dicts`_).
498 """ 487 """
499 id = self.__unpack_id(id) 488 id = self.__unpack_id(id)
500 return self.__api_request('GET', '/api/v1/accounts/{0}/featured_tags'.format(str(id))) 489 return self.__api_request('GET', f'/api/v1/accounts/{id}/featured_tags')
diff --git a/mastodon/admin.py b/mastodon/admin.py
index e2f5f20..422be35 100644
--- a/mastodon/admin.py
+++ b/mastodon/admin.py
@@ -142,7 +142,7 @@ class Mastodon(Internals):
142 Returns that dict. 142 Returns that dict.
143 """ 143 """
144 id = self.__unpack_id(id) 144 id = self.__unpack_id(id)
145 return self.__api_request('GET', '/api/v1/admin/accounts/{0}'.format(id)) 145 return self.__api_request('GET', f'/api/v1/admin/accounts/{id}')
146 146
147 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT) 147 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT)
148 def admin_account_enable(self, id): 148 def admin_account_enable(self, id):
@@ -152,7 +152,7 @@ class Mastodon(Internals):
152 Returns the updated :ref:`admin account dict <admin account dict>`. 152 Returns the updated :ref:`admin account dict <admin account dict>`.
153 """ 153 """
154 id = self.__unpack_id(id) 154 id = self.__unpack_id(id)
155 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/enable'.format(id)) 155 return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/enable')
156 156
157 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT) 157 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT)
158 def admin_account_approve(self, id): 158 def admin_account_approve(self, id):
@@ -162,7 +162,7 @@ class Mastodon(Internals):
162 Returns the updated :ref:`admin account dict <admin account dict>`. 162 Returns the updated :ref:`admin account dict <admin account dict>`.
163 """ 163 """
164 id = self.__unpack_id(id) 164 id = self.__unpack_id(id)
165 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/approve'.format(id)) 165 return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/approve')
166 166
167 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT) 167 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT)
168 def admin_account_reject(self, id): 168 def admin_account_reject(self, id):
@@ -172,7 +172,7 @@ class Mastodon(Internals):
172 Returns the updated :ref:`admin account dict <admin account dict>` for the account that is now gone. 172 Returns the updated :ref:`admin account dict <admin account dict>` for the account that is now gone.
173 """ 173 """
174 id = self.__unpack_id(id) 174 id = self.__unpack_id(id)
175 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/reject'.format(id)) 175 return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/reject')
176 176
177 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT) 177 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT)
178 def admin_account_unsilence(self, id): 178 def admin_account_unsilence(self, id):
@@ -182,7 +182,7 @@ class Mastodon(Internals):
182 Returns the updated :ref:`admin account dict <admin account dict>`. 182 Returns the updated :ref:`admin account dict <admin account dict>`.
183 """ 183 """
184 id = self.__unpack_id(id) 184 id = self.__unpack_id(id)
185 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsilence'.format(id)) 185 return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/unsilence')
186 186
187 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT) 187 @api_version("2.9.1", "2.9.1", _DICT_VERSION_ADMIN_ACCOUNT)
188 def admin_account_unsuspend(self, id): 188 def admin_account_unsuspend(self, id):
@@ -192,7 +192,7 @@ class Mastodon(Internals):
192 Returns the updated :ref:`admin account dict <admin account dict>`. 192 Returns the updated :ref:`admin account dict <admin account dict>`.
193 """ 193 """
194 id = self.__unpack_id(id) 194 id = self.__unpack_id(id)
195 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsuspend'.format(id)) 195 return self.__api_request('POST', f'/api/v1/admin/accounts/{id}/unsuspend')
196 196
197 @api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT) 197 @api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT)
198 def admin_account_delete(self, id): 198 def admin_account_delete(self, id):
@@ -202,7 +202,7 @@ class Mastodon(Internals):
202 The deleted accounts :ref:`admin account dict <admin account dict>`. 202 The deleted accounts :ref:`admin account dict <admin account dict>`.
203 """ 203 """
204 id = self.__unpack_id(id) 204 id = self.__unpack_id(id)
205 return self.__api_request('DELETE', '/api/v1/admin/accounts/{0}'.format(id)) 205 return self.__api_request('DELETE', f'/api/v1/admin/accounts/{id}')
206 206
207 @api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT) 207 @api_version("3.3.0", "3.3.0", _DICT_VERSION_ADMIN_ACCOUNT)
208 def admin_account_unsensitive(self, id): 208 def admin_account_unsensitive(self, id):
@@ -212,7 +212,7 @@ class Mastodon(Internals):
212 Returns the updated :ref:`admin account dict <admin account dict>`. 212 Returns the updated :ref:`admin account dict <admin account dict>`.
213 """ 213 """
214 id = self.__unpack_id(id) 214 id = self.__unpack_id(id)
215 return self.__api_request('POST', '/api/v1/admin/accounts/{0}/unsensitive'.format(id)) 215 return self.__api_request('POST', f'/api/v1/admin/accounts/{f}/unsensitive')
216 216
217 @api_version("2.9.1", "2.9.1", "2.9.1") 217 @api_version("2.9.1", "2.9.1", "2.9.1")
218 def admin_account_moderate(self, id, action=None, report_id=None, warning_preset_id=None, text=None, send_email_notification=True): 218 def admin_account_moderate(self, id, action=None, report_id=None, warning_preset_id=None, text=None, send_email_notification=True):
@@ -248,8 +248,7 @@ class Mastodon(Internals):
248 248
249 params["type"] = action 249 params["type"] = action
250 250
251 self.__api_request( 251 self.__api_request('POST', f'/api/v1/admin/accounts/{id}/action', params)
252 'POST', '/api/v1/admin/accounts/{0}/action'.format(id), params)
253 252
254 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT) 253 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
255 def admin_reports(self, resolved=False, account_id=None, target_account_id=None, max_id=None, min_id=None, since_id=None, limit=None): 254 def admin_reports(self, resolved=False, account_id=None, target_account_id=None, max_id=None, min_id=None, since_id=None, limit=None):
@@ -290,7 +289,7 @@ class Mastodon(Internals):
290 Returns a :ref:`report dict <report dict>`. 289 Returns a :ref:`report dict <report dict>`.
291 """ 290 """
292 id = self.__unpack_id(id) 291 id = self.__unpack_id(id)
293 return self.__api_request('GET', '/api/v1/admin/reports/{0}'.format(id)) 292 return self.__api_request('GET', f'/api/v1/admin/reports/{id}')
294 293
295 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT) 294 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
296 def admin_report_assign(self, id): 295 def admin_report_assign(self, id):
@@ -300,7 +299,7 @@ class Mastodon(Internals):
300 Returns the updated :ref:`report dict <report dict>`. 299 Returns the updated :ref:`report dict <report dict>`.
301 """ 300 """
302 id = self.__unpack_id(id) 301 id = self.__unpack_id(id)
303 return self.__api_request('POST', '/api/v1/admin/reports/{0}/assign_to_self'.format(id)) 302 return self.__api_request('POST', f'/api/v1/admin/reports/{id}/assign_to_self')
304 303
305 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT) 304 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
306 def admin_report_unassign(self, id): 305 def admin_report_unassign(self, id):
@@ -310,7 +309,7 @@ class Mastodon(Internals):
310 Returns the updated :ref:`report dict <report dict>`. 309 Returns the updated :ref:`report dict <report dict>`.
311 """ 310 """
312 id = self.__unpack_id(id) 311 id = self.__unpack_id(id)
313 return self.__api_request('POST', '/api/v1/admin/reports/{0}/unassign'.format(id)) 312 return self.__api_request('POST', f'/api/v1/admin/reports/{id}/unassign')
314 313
315 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT) 314 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
316 def admin_report_reopen(self, id): 315 def admin_report_reopen(self, id):
@@ -320,7 +319,7 @@ class Mastodon(Internals):
320 Returns the updated :ref:`report dict <report dict>`. 319 Returns the updated :ref:`report dict <report dict>`.
321 """ 320 """
322 id = self.__unpack_id(id) 321 id = self.__unpack_id(id)
323 return self.__api_request('POST', '/api/v1/admin/reports/{0}/reopen'.format(id)) 322 return self.__api_request('POST', f'/api/v1/admin/reports/{id}/reopen')
324 323
325 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT) 324 @api_version("2.9.1", "2.9.1", _DICT_VERSION_REPORT)
326 def admin_report_resolve(self, id): 325 def admin_report_resolve(self, id):
@@ -330,7 +329,7 @@ class Mastodon(Internals):
330 Returns the updated :ref:`report dict <report dict>`. 329 Returns the updated :ref:`report dict <report dict>`.
331 """ 330 """
332 id = self.__unpack_id(id) 331 id = self.__unpack_id(id)
333 return self.__api_request('POST', '/api/v1/admin/reports/{0}/resolve'.format(id)) 332 return self.__api_request('POST', f'/api/v1/admin/reports/{id}/resolve')
334 333
335 @api_version("3.5.0", "3.5.0", _DICT_VERSION_HASHTAG) 334 @api_version("3.5.0", "3.5.0", _DICT_VERSION_HASHTAG)
336 def admin_trending_tags(self, limit=None): 335 def admin_trending_tags(self, limit=None):
@@ -376,7 +375,7 @@ class Mastodon(Internals):
376 """ 375 """
377 if id is not None: 376 if id is not None:
378 id = self.__unpack_id(id) 377 id = self.__unpack_id(id)
379 return self.__api_request('GET', '/api/v1/admin/domain_blocks/{0}'.format(id)) 378 return self.__api_request('GET', f'/api/v1/admin/domain_blocks/{id}')
380 else: 379 else:
381 params = self.__generate_params(locals(),['limit']) 380 params = self.__generate_params(locals(),['limit'])
382 return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params) 381 return self.__api_request('GET', '/api/v1/admin/domain_blocks/', params)
@@ -430,7 +429,7 @@ class Mastodon(Internals):
430 raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.") 429 raise AttributeError("Must provide an id to modify the existing moderation actions on a given domain.")
431 id = self.__unpack_id(id) 430 id = self.__unpack_id(id)
432 params = self.__generate_params(locals(), ["id"]) 431 params = self.__generate_params(locals(), ["id"])
433 return self.__api_request('PUT', '/api/v1/admin/domain_blocks/{0}'.format(id), params) 432 return self.__api_request('PUT', f'/api/v1/admin/domain_blocks/{id}', params)
434 433
435 @api_version("4.0.0", "4.0.0", _DICT_VERSION_ADMIN_DOMAIN_BLOCK) 434 @api_version("4.0.0", "4.0.0", _DICT_VERSION_ADMIN_DOMAIN_BLOCK)
436 def admin_delete_domain_block(self, id=None): 435 def admin_delete_domain_block(self, id=None):
@@ -443,7 +442,7 @@ class Mastodon(Internals):
443 """ 442 """
444 if id is not None: 443 if id is not None:
445 id = self.__unpack_id(id) 444 id = self.__unpack_id(id)
446 self.__api_request('DELETE', '/api/v1/admin/domain_blocks/{0}'.format(id)) 445 self.__api_request('DELETE', f'/api/v1/admin/domain_blocks/{id}')
447 else: 446 else:
448 raise AttributeError("You must provide an id of an existing domain block to remove it.") 447 raise AttributeError("You must provide an id of an existing domain block to remove it.")
449 448
diff --git a/mastodon/authentication.py b/mastodon/authentication.py
index d4cb283..9f42587 100644
--- a/mastodon/authentication.py
+++ b/mastodon/authentication.py
@@ -61,13 +61,13 @@ class Mastodon(Internals):
61 if website is not None: 61 if website is not None:
62 request_data['website'] = website 62 request_data['website'] = website
63 if session: 63 if session:
64 ret = session.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout) 64 ret = session.post(f"{api_base_url}/api/v1/apps", data=request_data, timeout=request_timeout)
65 response = ret.json() 65 response = ret.json()
66 else: 66 else:
67 response = requests.post(api_base_url + '/api/v1/apps', data=request_data, timeout=request_timeout) 67 response = requests.post(f"{api_base_url}/api/v1/apps", data=request_data, timeout=request_timeout)
68 response = response.json() 68 response = response.json()
69 except Exception as e: 69 except Exception as e:
70 raise MastodonNetworkError("Could not complete request: %s" % e) 70 raise MastodonNetworkError(f"Could not complete request: {e}")
71 71
72 if to_file is not None: 72 if to_file is not None:
73 with open(to_file, 'w') as secret_file: 73 with open(to_file, 'w') as secret_file:
@@ -325,11 +325,11 @@ class Mastodon(Internals):
325 self.__set_token_expired(int(response.get('expires_in', 0))) 325 self.__set_token_expired(int(response.get('expires_in', 0)))
326 except Exception as e: 326 except Exception as e:
327 if username is not None or password is not None: 327 if username is not None or password is not None:
328 raise MastodonIllegalArgumentError('Invalid user name, password, or redirect_uris: %s' % e) 328 raise MastodonIllegalArgumentError(f'Invalid user name, password, or redirect_uris: {e}')
329 elif code is not None: 329 elif code is not None:
330 raise MastodonIllegalArgumentError('Invalid access token or redirect_uris: %s' % e) 330 raise MastodonIllegalArgumentError(f'Invalid access token or redirect_uris: {e}')
331 else: 331 else:
332 raise MastodonIllegalArgumentError('Invalid request: %s' % e) 332 raise MastodonIllegalArgumentError(f'Invalid request: {e}')
333 333
334 received_scopes = response["scope"].split(" ") 334 received_scopes = response["scope"].split(" ")
335 for scope_set in _SCOPE_SETS.keys(): 335 for scope_set in _SCOPE_SETS.keys():
diff --git a/mastodon/conversations.py b/mastodon/conversations.py
index ba3ee61..5482fb7 100644
--- a/mastodon/conversations.py
+++ b/mastodon/conversations.py
@@ -39,5 +39,4 @@ class Mastodon(Internals):
39 Returns the updated :ref:`conversation dict <conversation dict>`. 39 Returns the updated :ref:`conversation dict <conversation dict>`.
40 """ 40 """
41 id = self.__unpack_id(id) 41 id = self.__unpack_id(id)
42 url = '/api/v1/conversations/{0}/read'.format(str(id)) 42 return self.__api_request('POST', f'/api/v1/conversations/{id}/read')
43 return self.__api_request('POST', url)
diff --git a/mastodon/filters.py b/mastodon/filters.py
index 5f373d4..8841ba8 100644
--- a/mastodon/filters.py
+++ b/mastodon/filters.py
@@ -29,8 +29,7 @@ class Mastodon(Internals):
29 Returns a :ref:`filter dict <filter dict>`. 29 Returns a :ref:`filter dict <filter dict>`.
30 """ 30 """
31 id = self.__unpack_id(id) 31 id = self.__unpack_id(id)
32 url = '/api/v1/filters/{0}'.format(str(id)) 32 return self.__api_request('GET', f'/api/v1/filters/{id}')
33 return self.__api_request('GET', url)
34 33
35 @api_version("2.4.3", "2.4.3", _DICT_VERSION_FILTER) 34 @api_version("2.4.3", "2.4.3", _DICT_VERSION_FILTER)
36 def filters_apply(self, objects, filters, context): 35 def filters_apply(self, objects, filters, context):
@@ -106,8 +105,7 @@ class Mastodon(Internals):
106 """ 105 """
107 id = self.__unpack_id(id) 106 id = self.__unpack_id(id)
108 params = self.__generate_params(locals(), ['id']) 107 params = self.__generate_params(locals(), ['id'])
109 url = '/api/v1/filters/{0}'.format(str(id)) 108 return self.__api_request('PUT', f'/api/v1/filters/{id}', params)
110 return self.__api_request('PUT', url, params)
111 109
112 @api_version("2.4.3", "2.4.3", "2.4.3") 110 @api_version("2.4.3", "2.4.3", "2.4.3")
113 def filter_delete(self, id): 111 def filter_delete(self, id):
@@ -115,5 +113,4 @@ class Mastodon(Internals):
115 Deletes the filter with the given `id`. 113 Deletes the filter with the given `id`.
116 """ 114 """
117 id = self.__unpack_id(id) 115 id = self.__unpack_id(id)
118 url = '/api/v1/filters/{0}'.format(str(id)) 116 self.__api_request('DELETE', f'/api/v1/filters/{id}')
119 self.__api_request('DELETE', url) \ No newline at end of file
diff --git a/mastodon/hashtags.py b/mastodon/hashtags.py
index 89e8cac..f894c11 100644
--- a/mastodon/hashtags.py
+++ b/mastodon/hashtags.py
@@ -47,6 +47,4 @@ class Mastodon(Internals):
47 Deletes one of the logged-in user's featured hashtags. 47 Deletes one of the logged-in user's featured hashtags.
48 """ 48 """
49 id = self.__unpack_id(id) 49 id = self.__unpack_id(id)
50 url = '/api/v1/featured_tags/{0}'.format(str(id)) 50 self.__api_request('DELETE', f'/api/v1/featured_tags/{id}')
51 self.__api_request('DELETE', url)
52 \ No newline at end of file
diff --git a/mastodon/instance.py b/mastodon/instance.py
index dfbbefb..1217596 100644
--- a/mastodon/instance.py
+++ b/mastodon/instance.py
@@ -156,8 +156,7 @@ class Mastodon(Internals):
156 """ 156 """
157 id = self.__unpack_id(id) 157 id = self.__unpack_id(id)
158 158
159 url = '/api/v1/announcements/{0}/dismiss'.format(str(id)) 159 self.__api_request('POST', f'/api/v1/announcements/{id}/dismiss')
160 self.__api_request('POST', url)
161 160
162 @api_version("3.1.0", "3.1.0", "3.1.0") 161 @api_version("3.1.0", "3.1.0", "3.1.0")
163 def announcement_reaction_create(self, id, reaction): 162 def announcement_reaction_create(self, id, reaction):
@@ -171,9 +170,7 @@ class Mastodon(Internals):
171 """ 170 """
172 id = self.__unpack_id(id) 171 id = self.__unpack_id(id)
173 172
174 url = '/api/v1/announcements/{0}/reactions/{1}'.format( 173 self.__api_request('PUT', f'/api/v1/announcements/{id}/reactions/{reaction}')
175 str(id), reaction)
176 self.__api_request('PUT', url)
177 174
178 @api_version("3.1.0", "3.1.0", "3.1.0") 175 @api_version("3.1.0", "3.1.0", "3.1.0")
179 def announcement_reaction_delete(self, id, reaction): 176 def announcement_reaction_delete(self, id, reaction):
@@ -184,6 +181,4 @@ class Mastodon(Internals):
184 """ 181 """
185 id = self.__unpack_id(id) 182 id = self.__unpack_id(id)
186 183
187 url = '/api/v1/announcements/{0}/reactions/{1}'.format( 184 self.__api_request('DELETE', f'/api/v1/announcements/{id}/reactions/{reaction}')
188 str(id), reaction)
189 self.__api_request('DELETE', url)
diff --git a/mastodon/internals.py b/mastodon/internals.py
index 758a1d4..d94a116 100644
--- a/mastodon/internals.py
+++ b/mastodon/internals.py
@@ -182,11 +182,10 @@ class Mastodon():
182 base_url = base_url_override 182 base_url = base_url_override
183 183
184 if self.debug_requests: 184 if self.debug_requests:
185 print('Mastodon: Request to endpoint "' + base_url + 185 print(f'Mastodon: Request to endpoint "{base_url}{endpoint}" using method "{method}".')
186 endpoint + '" using method "' + method + '".') 186 print(f'Parameters: {params}')
187 print('Parameters: ' + str(params)) 187 print(f'Headers: {headers}')
188 print('Headers: ' + str(headers)) 188 print(f'Files: {files}')
189 print('Files: ' + str(files))
190 189
191 # Make request 190 # Make request
192 request_complete = False 191 request_complete = False
@@ -205,7 +204,7 @@ class Mastodon():
205 204
206 response_object = self.session.request(method, base_url + endpoint, **kwargs) 205 response_object = self.session.request(method, base_url + endpoint, **kwargs)
207 except Exception as e: 206 except Exception as e:
208 raise MastodonNetworkError("Could not complete request: %s" % e) 207 raise MastodonNetworkError(f"Could not complete request: {e}")
209 208
210 if response_object is None: 209 if response_object is None:
211 raise MastodonIllegalArgumentError("Illegal request.") 210 raise MastodonIllegalArgumentError("Illegal request.")
@@ -219,8 +218,7 @@ class Mastodon():
219 218
220 # For gotosocial, we need an int representation, but for non-ints this would crash 219 # For gotosocial, we need an int representation, but for non-ints this would crash
221 try: 220 try:
222 ratelimit_intrep = str( 221 ratelimit_intrep = str(int(response_object.headers['X-RateLimit-Reset']))
223 int(response_object.headers['X-RateLimit-Reset']))
224 except: 222 except:
225 ratelimit_intrep = None 223 ratelimit_intrep = None
226 224
@@ -240,13 +238,13 @@ class Mastodon():
240 self.ratelimit_reset += server_time_diff 238 self.ratelimit_reset += server_time_diff
241 self.ratelimit_lastcall = time.time() 239 self.ratelimit_lastcall = time.time()
242 except Exception as e: 240 except Exception as e:
243 raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e) 241 raise MastodonRatelimitError(f"Rate limit time calculations failed: {e}")
244 242
245 # Handle response 243 # Handle response
246 if self.debug_requests: 244 if self.debug_requests:
247 print('Mastodon: Response received with code ' + str(response_object.status_code) + '.') 245 print(f'Mastodon: Response received with code {response_object.status_code}.')
248 print('response headers: ' + str(response_object.headers)) 246 print(f'response headers: {response_object.headers}')
249 print('Response text content: ' + str(response_object.text)) 247 print(f'Response text content: {response_object.text}')
250 248
251 if not response_object.ok: 249 if not response_object.ok:
252 try: 250 try:
@@ -306,9 +304,9 @@ class Mastodon():
306 response = response_object.json(object_hook=self.__json_hooks) 304 response = response_object.json(object_hook=self.__json_hooks)
307 except: 305 except:
308 raise MastodonAPIError( 306 raise MastodonAPIError(
309 "Could not parse response as JSON, response code was %s, " 307 f"Could not parse response as JSON, response code was {response_object.status_code}, "
310 "bad json content was '%s'" % (response_object.status_code, 308 f"bad json content was {response_object.content!r}."
311 response_object.content)) 309 )
312 else: 310 else:
313 response = response_object.content 311 response = response_object.content
314 312
@@ -413,8 +411,8 @@ class Mastodon():
413 url = "http://" + parse.netloc 411 url = "http://" + parse.netloc
414 else: 412 else:
415 raise MastodonAPIError( 413 raise MastodonAPIError(
416 "Could not parse streaming api location returned from server: {}.".format( 414 f"Could not parse streaming api location returned from server: {instance['urls']['streaming_api']}."
417 instance["urls"]["streaming_api"])) 415 )
418 else: 416 else:
419 url = self.api_base_url 417 url = self.api_base_url
420 return url 418 return url
@@ -436,16 +434,14 @@ class Mastodon():
436 434
437 # Connect function (called and then potentially passed to async handler) 435 # Connect function (called and then potentially passed to async handler)
438 def connect_func(): 436 def connect_func():
439 headers = {"Authorization": "Bearer " + 437 headers = {"Authorization": "Bearer " + self.access_token} if self.access_token else {}
440 self.access_token} if self.access_token else {}
441 if self.user_agent: 438 if self.user_agent:
442 headers['User-Agent'] = self.user_agent 439 headers['User-Agent'] = self.user_agent
443 connection = self.session.get(url + endpoint, headers=headers, data=params, stream=True, 440 connection = self.session.get(url + endpoint, headers=headers, data=params, stream=True,
444 timeout=(self.request_timeout, timeout)) 441 timeout=(self.request_timeout, timeout))
445 442
446 if connection.status_code != 200: 443 if connection.status_code != 200:
447 raise MastodonNetworkError( 444 raise MastodonNetworkError(f"Could not connect to streaming server: {connection.reason}")
448 "Could not connect to streaming server: %s" % connection.reason)
449 return connection 445 return connection
450 connection = None 446 connection = None
451 447
@@ -638,7 +634,7 @@ class Mastodon():
638 raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.') 634 raise MastodonIllegalArgumentError('Could not determine mime type or data passed directly without mime type.')
639 if file_name is None: 635 if file_name is None:
640 random_suffix = uuid.uuid4().hex 636 random_suffix = uuid.uuid4().hex
641 file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension(mime_type) 637 file_name = f"mastodonpyupload_{time.time()}_{random_suffix}{mimetypes.guess_extension(mime_type)}"
642 return (file_name, media_file, mime_type) 638 return (file_name, media_file, mime_type)
643 639
644 @staticmethod 640 @staticmethod
diff --git a/mastodon/lists.py b/mastodon/lists.py
index 0882133..57ced46 100644
--- a/mastodon/lists.py
+++ b/mastodon/lists.py
@@ -26,7 +26,7 @@ class Mastodon(Internals):
26 Returns a :ref:`list dict <list dict>`. 26 Returns a :ref:`list dict <list dict>`.
27 """ 27 """
28 id = self.__unpack_id(id) 28 id = self.__unpack_id(id)
29 return self.__api_request('GET', '/api/v1/lists/{0}'.format(id)) 29 return self.__api_request('GET', f'/api/v1/lists/{id}')
30 30
31 @api_version("2.1.0", "2.6.0", _DICT_VERSION_ACCOUNT) 31 @api_version("2.1.0", "2.6.0", _DICT_VERSION_ACCOUNT)
32 def list_accounts(self, id, max_id=None, min_id=None, since_id=None, limit=None): 32 def list_accounts(self, id, max_id=None, min_id=None, since_id=None, limit=None):
@@ -47,7 +47,7 @@ class Mastodon(Internals):
47 since_id = self.__unpack_id(since_id, dateconv=True) 47 since_id = self.__unpack_id(since_id, dateconv=True)
48 48
49 params = self.__generate_params(locals(), ['id']) 49 params = self.__generate_params(locals(), ['id'])
50 return self.__api_request('GET', '/api/v1/lists/{0}/accounts'.format(id)) 50 return self.__api_request('GET', f'/api/v1/lists/{id}/accounts')
51 51
52 ### 52 ###
53 # Writing data: Lists 53 # Writing data: Lists
@@ -71,7 +71,7 @@ class Mastodon(Internals):
71 """ 71 """
72 id = self.__unpack_id(id) 72 id = self.__unpack_id(id)
73 params = self.__generate_params(locals(), ['id']) 73 params = self.__generate_params(locals(), ['id'])
74 return self.__api_request('PUT', '/api/v1/lists/{0}'.format(id), params) 74 return self.__api_request('PUT', f'/api/v1/lists/{id}', params)
75 75
76 @api_version("2.1.0", "2.1.0", "2.1.0") 76 @api_version("2.1.0", "2.1.0", "2.1.0")
77 def list_delete(self, id): 77 def list_delete(self, id):
@@ -79,7 +79,7 @@ class Mastodon(Internals):
79 Delete a list. 79 Delete a list.
80 """ 80 """
81 id = self.__unpack_id(id) 81 id = self.__unpack_id(id)
82 self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id)) 82 self.__api_request('DELETE', f'/api/v1/lists/{id}')
83 83
84 @api_version("2.1.0", "2.1.0", "2.1.0") 84 @api_version("2.1.0", "2.1.0", "2.1.0")
85 def list_accounts_add(self, id, account_ids): 85 def list_accounts_add(self, id, account_ids):
@@ -93,8 +93,7 @@ class Mastodon(Internals):
93 account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) 93 account_ids = list(map(lambda x: self.__unpack_id(x), account_ids))
94 94
95 params = self.__generate_params(locals(), ['id']) 95 params = self.__generate_params(locals(), ['id'])
96 self.__api_request( 96 self.__api_request('POST', f'/api/v1/lists/{id}/accounts', params)
97 'POST', '/api/v1/lists/{0}/accounts'.format(id), params)
98 97
99 @api_version("2.1.0", "2.1.0", "2.1.0") 98 @api_version("2.1.0", "2.1.0", "2.1.0")
100 def list_accounts_delete(self, id, account_ids): 99 def list_accounts_delete(self, id, account_ids):
@@ -108,5 +107,4 @@ class Mastodon(Internals):
108 account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) 107 account_ids = list(map(lambda x: self.__unpack_id(x), account_ids))
109 108
110 params = self.__generate_params(locals(), ['id']) 109 params = self.__generate_params(locals(), ['id'])
111 self.__api_request( 110 self.__api_request('DELETE', f'/api/v1/lists/{id}/accounts', params) \ No newline at end of file
112 'DELETE', '/api/v1/lists/{0}/accounts'.format(id), params) \ No newline at end of file
diff --git a/mastodon/media.py b/mastodon/media.py
index 3c815fb..41843a6 100644
--- a/mastodon/media.py
+++ b/mastodon/media.py
@@ -19,7 +19,7 @@ class Mastodon(Internals):
19 to the logged-in user. 19 to the logged-in user.
20 """ 20 """
21 id = self.__unpack_id(id) 21 id = self.__unpack_id(id)
22 return self.__api_request('GET', '/api/v1/media/{0}'.format(str(id))) 22 return self.__api_request('GET', f'/api/v1/media/{id}')
23 23
24 ### 24 ###
25 # Writing data: Media 25 # Writing data: Media
@@ -57,7 +57,7 @@ class Mastodon(Internals):
57 media_file, mime_type, file_name)} 57 media_file, mime_type, file_name)}
58 58
59 if focus is not None: 59 if focus is not None:
60 focus = str(focus[0]) + "," + str(focus[1]) 60 focus = f"{focus[0]},{focus[1]}"
61 61
62 if thumbnail is not None: 62 if thumbnail is not None:
63 if not self.verify_minimum_version("3.2.0", cached=True): 63 if not self.verify_minimum_version("3.2.0", cached=True):
@@ -99,7 +99,7 @@ class Mastodon(Internals):
99 id = self.__unpack_id(id) 99 id = self.__unpack_id(id)
100 100
101 if focus is not None: 101 if focus is not None:
102 focus = str(focus[0]) + "," + str(focus[1]) 102 focus = f"{focus[0]},{focus[1]}"
103 103
104 params = self.__generate_params( 104 params = self.__generate_params(
105 locals(), ['id', 'thumbnail', 'thumbnail_mime_type']) 105 locals(), ['id', 'thumbnail', 'thumbnail_mime_type'])
@@ -109,6 +109,6 @@ class Mastodon(Internals):
109 raise MastodonVersionError('Thumbnail requires version > 3.2.0') 109 raise MastodonVersionError('Thumbnail requires version > 3.2.0')
110 files = {"thumbnail": self.__load_media_file( 110 files = {"thumbnail": self.__load_media_file(
111 thumbnail, thumbnail_mime_type)} 111 thumbnail, thumbnail_mime_type)}
112 return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params, files=files) 112 return self.__api_request('PUT', f'/api/v1/media/{id}', params, files=files)
113 else: 113 else:
114 return self.__api_request('PUT', '/api/v1/media/{0}'.format(str(id)), params) 114 return self.__api_request('PUT', f'/api/v1/media/{id}', params)
diff --git a/mastodon/notifications.py b/mastodon/notifications.py
index f65b3fb..6d2d1f7 100644
--- a/mastodon/notifications.py
+++ b/mastodon/notifications.py
@@ -64,8 +64,7 @@ class Mastodon(Internals):
64 return self.__api_request('GET', '/api/v1/notifications', params) 64 return self.__api_request('GET', '/api/v1/notifications', params)
65 else: 65 else:
66 id = self.__unpack_id(id) 66 id = self.__unpack_id(id)
67 url = '/api/v1/notifications/{0}'.format(str(id)) 67 return self.__api_request('GET', f"/api/v1/notifications/{id}")
68 return self.__api_request('GET', url)
69 68
70 ### 69 ###
71 # Writing data: Notifications 70 # Writing data: Notifications
@@ -85,8 +84,7 @@ class Mastodon(Internals):
85 id = self.__unpack_id(id) 84 id = self.__unpack_id(id)
86 85
87 if self.verify_minimum_version("2.9.2", cached=True): 86 if self.verify_minimum_version("2.9.2", cached=True):
88 url = '/api/v1/notifications/{0}/dismiss'.format(str(id)) 87 self.__api_request('POST', f'/api/v1/notifications/{id}/dismiss')
89 self.__api_request('POST', url)
90 else: 88 else:
91 params = self.__generate_params(locals()) 89 params = self.__generate_params(locals())
92 self.__api_request('POST', '/api/v1/notifications/dismiss', params) 90 self.__api_request('POST', '/api/v1/notifications/dismiss', params)
diff --git a/mastodon/polls.py b/mastodon/polls.py
index d974531..2722ba8 100644
--- a/mastodon/polls.py
+++ b/mastodon/polls.py
@@ -17,8 +17,7 @@ class Mastodon(Internals):
17 Returns a :ref:`poll dict <poll dict>`. 17 Returns a :ref:`poll dict <poll dict>`.
18 """ 18 """
19 id = self.__unpack_id(id) 19 id = self.__unpack_id(id)
20 url = '/api/v1/polls/{0}'.format(str(id)) 20 return self.__api_request('GET', f'/api/v1/polls/{id}')
21 return self.__api_request('GET', url)
22 21
23 ### 22 ###
24 # Writing data: Polls 23 # Writing data: Polls
@@ -44,9 +43,8 @@ class Mastodon(Internals):
44 choices = [choices] 43 choices = [choices]
45 params = self.__generate_params(locals(), ['id']) 44 params = self.__generate_params(locals(), ['id'])
46 45
47 url = '/api/v1/polls/{0}/votes'.format(id) 46 self.__api_request('POST', f'/api/v1/polls/{id}/votes', params)
48 self.__api_request('POST', url, params) 47
49
50 def make_poll(self, options, expires_in, multiple=False, hide_totals=False): 48 def make_poll(self, options, expires_in, multiple=False, hide_totals=False):
51 """ 49 """
52 Generate a poll object that can be passed as the `poll` option when posting a status. 50 Generate a poll object that can be passed as the `poll` option when posting a status.
diff --git a/mastodon/relationships.py b/mastodon/relationships.py
index 9cf15db..043174c 100644
--- a/mastodon/relationships.py
+++ b/mastodon/relationships.py
@@ -102,8 +102,7 @@ class Mastodon(Internals):
102 Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account. 102 Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account.
103 """ 103 """
104 id = self.__unpack_id(id) 104 id = self.__unpack_id(id)
105 url = '/api/v1/follow_requests/{0}/authorize'.format(str(id)) 105 return self.__api_request('POST', f'/api/v1/follow_requests/{id}/authorize')
106 return self.__api_request('POST', url)
107 106
108 @api_version("1.0.0", "3.0.0", _DICT_VERSION_RELATIONSHIP) 107 @api_version("1.0.0", "3.0.0", _DICT_VERSION_RELATIONSHIP)
109 def follow_request_reject(self, id): 108 def follow_request_reject(self, id):
@@ -113,8 +112,7 @@ class Mastodon(Internals):
113 Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account. 112 Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account.
114 """ 113 """
115 id = self.__unpack_id(id) 114 id = self.__unpack_id(id)
116 url = '/api/v1/follow_requests/{0}/reject'.format(str(id)) 115 return self.__api_request('POST', f'/api/v1/follow_requests/{id}/reject')
117 return self.__api_request('POST', url)
118 116
119 ### 117 ###
120 # Writing data: Domain blocks 118 # Writing data: Domain blocks
diff --git a/mastodon/statuses.py b/mastodon/statuses.py
index 36a7d2b..eb372d8 100644
--- a/mastodon/statuses.py
+++ b/mastodon/statuses.py
@@ -23,8 +23,7 @@ class Mastodon(Internals):
23 Returns a :ref:`status dict <status dict>`. 23 Returns a :ref:`status dict <status dict>`.
24 """ 24 """
25 id = self.__unpack_id(id) 25 id = self.__unpack_id(id)
26 url = '/api/v1/statuses/{0}'.format(str(id)) 26 return self.__api_request('GET', f'/api/v1/statuses/{id}')
27 return self.__api_request('GET', url)
28 27
29 @api_version("1.0.0", "3.0.0", _DICT_VERSION_CARD) 28 @api_version("1.0.0", "3.0.0", _DICT_VERSION_CARD)
30 def status_card(self, id): 29 def status_card(self, id):
@@ -45,8 +44,7 @@ class Mastodon(Internals):
45 return self.status(id).card 44 return self.status(id).card
46 else: 45 else:
47 id = self.__unpack_id(id) 46 id = self.__unpack_id(id)
48 url = '/api/v1/statuses/{0}/card'.format(str(id)) 47 return self.__api_request('GET', f'/api/v1/statuses/{id}/card')
49 return self.__api_request('GET', url)
50 48
51 @api_version("1.0.0", "1.0.0", _DICT_VERSION_CONTEXT) 49 @api_version("1.0.0", "1.0.0", _DICT_VERSION_CONTEXT)
52 def status_context(self, id): 50 def status_context(self, id):
@@ -58,8 +56,7 @@ class Mastodon(Internals):
58 Returns a :ref:`context dict <context dict>`. 56 Returns a :ref:`context dict <context dict>`.
59 """ 57 """
60 id = self.__unpack_id(id) 58 id = self.__unpack_id(id)
61 url = '/api/v1/statuses/{0}/context'.format(str(id)) 59 return self.__api_request('GET', f'/api/v1/statuses/{id}/context')
62 return self.__api_request('GET', url)
63 60
64 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) 61 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
65 def status_reblogged_by(self, id): 62 def status_reblogged_by(self, id):
@@ -71,8 +68,7 @@ class Mastodon(Internals):
71 Returns a list of :ref:`account dicts <account dicts>`. 68 Returns a list of :ref:`account dicts <account dicts>`.
72 """ 69 """
73 id = self.__unpack_id(id) 70 id = self.__unpack_id(id)
74 url = '/api/v1/statuses/{0}/reblogged_by'.format(str(id)) 71 return self.__api_request('GET', f'/api/v1/statuses/{id}/reblogged_by')
75 return self.__api_request('GET', url)
76 72
77 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT) 73 @api_version("1.0.0", "2.1.0", _DICT_VERSION_ACCOUNT)
78 def status_favourited_by(self, id): 74 def status_favourited_by(self, id):
@@ -84,8 +80,7 @@ class Mastodon(Internals):
84 Returns a list of :ref:`account dicts <account dicts>`. 80 Returns a list of :ref:`account dicts <account dicts>`.
85 """ 81 """
86 id = self.__unpack_id(id) 82 id = self.__unpack_id(id)
87 url = '/api/v1/statuses/{0}/favourited_by'.format(str(id)) 83 return self.__api_request('GET', f'/api/v1/statuses/{id}/favourited_by')
88 return self.__api_request('GET', url)
89 84
90 ### 85 ###
91 # Reading data: Scheduled statuses 86 # Reading data: Scheduled statuses
@@ -107,9 +102,8 @@ class Mastodon(Internals):
107 Returns a :ref:`scheduled status dict <scheduled status dict>`. 102 Returns a :ref:`scheduled status dict <scheduled status dict>`.
108 """ 103 """
109 id = self.__unpack_id(id) 104 id = self.__unpack_id(id)
110 url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) 105 return self.__api_request('GET', f'/api/v1/scheduled_statuses/{id}')
111 return self.__api_request('GET', url) 106
112
113 ### 107 ###
114 # Writing data: Statuses 108 # Writing data: Statuses
115 ### 109 ###
@@ -150,7 +144,7 @@ class Mastodon(Internals):
150 else: 144 else:
151 params_initial['visibility'] = params_initial['visibility'].lower() 145 params_initial['visibility'] = params_initial['visibility'].lower()
152 if params_initial['visibility'] not in valid_visibilities: 146 if params_initial['visibility'] not in valid_visibilities:
153 raise ValueError('Invalid visibility value! Acceptable values are %s' % valid_visibilities) 147 raise ValueError(f'Invalid visibility value! Acceptable values are {valid_visibilities}')
154 148
155 if params_initial['language'] is None: 149 if params_initial['language'] is None:
156 del params_initial['language'] 150 del params_initial['language']
@@ -170,7 +164,7 @@ class Mastodon(Internals):
170 for media_id in media_ids: 164 for media_id in media_ids:
171 media_ids_proper.append(self.__unpack_id(media_id)) 165 media_ids_proper.append(self.__unpack_id(media_id))
172 except Exception as e: 166 except Exception as e:
173 raise MastodonIllegalArgumentError("Invalid media dict: %s" % e) 167 raise MastodonIllegalArgumentError(f"Invalid media dict: {e}")
174 168
175 params_initial["media_ids"] = media_ids_proper 169 params_initial["media_ids"] = media_ids_proper
176 170
@@ -187,7 +181,7 @@ class Mastodon(Internals):
187 return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json) 181 return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json)
188 else: 182 else:
189 # Edit 183 # Edit
190 return self.__api_request('PUT', '/api/v1/statuses/{0}'.format(str(self.__unpack_id(edit))), params, headers=headers, use_json=use_json) 184 return self.__api_request('PUT', f'/api/v1/statuses/{self.__unpack_id(edit)}', params, headers=headers, use_json=use_json)
191 185
192 @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS) 186 @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS)
193 def status_post(self, status, in_reply_to_id=None, media_ids=None, 187 def status_post(self, status, in_reply_to_id=None, media_ids=None,
@@ -303,7 +297,7 @@ class Mastodon(Internals):
303 will have three, and so on. 297 will have three, and so on.
304 """ 298 """
305 id = self.__unpack_id(id) 299 id = self.__unpack_id(id)
306 return self.__api_request('GET', "/api/v1/statuses/{0}/history".format(str(id))) 300 return self.__api_request('GET', f"/api/v1/statuses/{id}/history")
307 301
308 def status_source(self, id): 302 def status_source(self, id):
309 """ 303 """
@@ -314,7 +308,7 @@ class Mastodon(Internals):
314 instead. 308 instead.
315 """ 309 """
316 id = self.__unpack_id(id) 310 id = self.__unpack_id(id)
317 return self.__api_request('GET', "/api/v1/statuses/{0}/source".format(str(id))) 311 return self.__api_request('GET', f"/api/v1/statuses/{id}/source")
318 312
319 @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS) 313 @api_version("1.0.0", "2.8.0", _DICT_VERSION_STATUS)
320 def status_reply(self, to_status, status, in_reply_to_id=None, media_ids=None, 314 def status_reply(self, to_status, status, in_reply_to_id=None, media_ids=None,
@@ -372,8 +366,7 @@ class Mastodon(Internals):
372 "delete and redraft" functionality) 366 "delete and redraft" functionality)
373 """ 367 """
374 id = self.__unpack_id(id) 368 id = self.__unpack_id(id)
375 url = '/api/v1/statuses/{0}'.format(str(id)) 369 return self.__api_request('DELETE', f'/api/v1/statuses/{id}')
376 return self.__api_request('DELETE', url)
377 370
378 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) 371 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
379 def status_reblog(self, id, visibility=None): 372 def status_reblog(self, id, visibility=None):
@@ -390,12 +383,10 @@ class Mastodon(Internals):
390 if 'visibility' in params: 383 if 'visibility' in params:
391 params['visibility'] = params['visibility'].lower() 384 params['visibility'] = params['visibility'].lower()
392 if params['visibility'] not in valid_visibilities: 385 if params['visibility'] not in valid_visibilities:
393 raise ValueError('Invalid visibility value! Acceptable ' 386 raise ValueError(f'Invalid visibility value! Acceptable values are {valid_visibilities}')
394 'values are %s' % valid_visibilities)
395 387
396 id = self.__unpack_id(id) 388 id = self.__unpack_id(id)
397 url = '/api/v1/statuses/{0}/reblog'.format(str(id)) 389 return self.__api_request('POST', f'/api/v1/statuses/{id}/reblog', params)
398 return self.__api_request('POST', url, params)
399 390
400 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) 391 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
401 def status_unreblog(self, id): 392 def status_unreblog(self, id):
@@ -405,8 +396,7 @@ class Mastodon(Internals):
405 Returns a :ref:`status dict <status dict>` with the status that used to be reblogged. 396 Returns a :ref:`status dict <status dict>` with the status that used to be reblogged.
406 """ 397 """
407 id = self.__unpack_id(id) 398 id = self.__unpack_id(id)
408 url = '/api/v1/statuses/{0}/unreblog'.format(str(id)) 399 return self.__api_request('POST', f'/api/v1/statuses/{id}/unreblog')
409 return self.__api_request('POST', url)
410 400
411 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) 401 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
412 def status_favourite(self, id): 402 def status_favourite(self, id):
@@ -416,8 +406,7 @@ class Mastodon(Internals):
416 Returns a :ref:`status dict <status dict>` with the favourited status. 406 Returns a :ref:`status dict <status dict>` with the favourited status.
417 """ 407 """
418 id = self.__unpack_id(id) 408 id = self.__unpack_id(id)
419 url = '/api/v1/statuses/{0}/favourite'.format(str(id)) 409 return self.__api_request('POST', f'/api/v1/statuses/{id}/favourite')
420 return self.__api_request('POST', url)
421 410
422 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS) 411 @api_version("1.0.0", "2.0.0", _DICT_VERSION_STATUS)
423 def status_unfavourite(self, id): 412 def status_unfavourite(self, id):
@@ -427,8 +416,7 @@ class Mastodon(Internals):
427 Returns a :ref:`status dict <status dict>` with the un-favourited status. 416 Returns a :ref:`status dict <status dict>` with the un-favourited status.
428 """ 417 """
429 id = self.__unpack_id(id) 418 id = self.__unpack_id(id)
430 url = '/api/v1/statuses/{0}/unfavourite'.format(str(id)) 419 return self.__api_request('POST', f'/api/v1/statuses/{id}/unfavourite')
431 return self.__api_request('POST', url)
432 420
433 @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS) 421 @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS)
434 def status_mute(self, id): 422 def status_mute(self, id):
@@ -438,8 +426,7 @@ class Mastodon(Internals):
438 Returns a :ref:`status dict <status dict>` with the now muted status 426 Returns a :ref:`status dict <status dict>` with the now muted status
439 """ 427 """
440 id = self.__unpack_id(id) 428 id = self.__unpack_id(id)
441 url = '/api/v1/statuses/{0}/mute'.format(str(id)) 429 return self.__api_request('POST', f'/api/v1/statuses/{id}/mute')
442 return self.__api_request('POST', url)
443 430
444 @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS) 431 @api_version("1.4.0", "2.0.0", _DICT_VERSION_STATUS)
445 def status_unmute(self, id): 432 def status_unmute(self, id):
@@ -449,8 +436,7 @@ class Mastodon(Internals):
449 Returns a :ref:`status dict <status dict>` with the status that used to be muted. 436 Returns a :ref:`status dict <status dict>` with the status that used to be muted.
450 """ 437 """
451 id = self.__unpack_id(id) 438 id = self.__unpack_id(id)
452 url = '/api/v1/statuses/{0}/unmute'.format(str(id)) 439 return self.__api_request('POST', f'/api/v1/statuses/{id}/unmute')
453 return self.__api_request('POST', url)
454 440
455 @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS) 441 @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
456 def status_pin(self, id): 442 def status_pin(self, id):
@@ -460,8 +446,7 @@ class Mastodon(Internals):
460 Returns a :ref:`status dict <status dict>` with the now pinned status 446 Returns a :ref:`status dict <status dict>` with the now pinned status
461 """ 447 """
462 id = self.__unpack_id(id) 448 id = self.__unpack_id(id)
463 url = '/api/v1/statuses/{0}/pin'.format(str(id)) 449 return self.__api_request('POST', f'/api/v1/statuses/{id}/pin')
464 return self.__api_request('POST', url)
465 450
466 @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS) 451 @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
467 def status_unpin(self, id): 452 def status_unpin(self, id):
@@ -471,8 +456,7 @@ class Mastodon(Internals):
471 Returns a :ref:`status dict <status dict>` with the status that used to be pinned. 456 Returns a :ref:`status dict <status dict>` with the status that used to be pinned.
472 """ 457 """
473 id = self.__unpack_id(id) 458 id = self.__unpack_id(id)
474 url = '/api/v1/statuses/{0}/unpin'.format(str(id)) 459 return self.__api_request('POST', f'/api/v1/statuses/{id}/unpin')
475 return self.__api_request('POST', url)
476 460
477 @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS) 461 @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS)
478 def status_bookmark(self, id): 462 def status_bookmark(self, id):
@@ -482,8 +466,7 @@ class Mastodon(Internals):
482 Returns a :ref:`status dict <status dict>` with the now bookmarked status 466 Returns a :ref:`status dict <status dict>` with the now bookmarked status
483 """ 467 """
484 id = self.__unpack_id(id) 468 id = self.__unpack_id(id)
485 url = '/api/v1/statuses/{0}/bookmark'.format(str(id)) 469 return self.__api_request('POST', f'/api/v1/statuses/{id}/bookmark')
486 return self.__api_request('POST', url)
487 470
488 @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS) 471 @api_version("3.1.0", "3.1.0", _DICT_VERSION_STATUS)
489 def status_unbookmark(self, id): 472 def status_unbookmark(self, id):
@@ -493,8 +476,7 @@ class Mastodon(Internals):
493 Returns a :ref:`status dict <status dict>` with the status that used to be bookmarked. 476 Returns a :ref:`status dict <status dict>` with the status that used to be bookmarked.
494 """ 477 """
495 id = self.__unpack_id(id) 478 id = self.__unpack_id(id)
496 url = '/api/v1/statuses/{0}/unbookmark'.format(str(id)) 479 return self.__api_request('POST', f'/api/v1/statuses/{id}/unbookmark')
497 return self.__api_request('POST', url)
498 480
499 ### 481 ###
500 # Writing data: Scheduled statuses 482 # Writing data: Scheduled statuses
@@ -511,8 +493,7 @@ class Mastodon(Internals):
511 scheduled_at = self.__consistent_isoformat_utc(scheduled_at) 493 scheduled_at = self.__consistent_isoformat_utc(scheduled_at)
512 id = self.__unpack_id(id) 494 id = self.__unpack_id(id)
513 params = self.__generate_params(locals(), ['id']) 495 params = self.__generate_params(locals(), ['id'])
514 url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) 496 return self.__api_request('PUT', f'/api/v1/scheduled_statuses/{id}', params)
515 return self.__api_request('PUT', url, params)
516 497
517 @api_version("2.7.0", "2.7.0", "2.7.0") 498 @api_version("2.7.0", "2.7.0", "2.7.0")
518 def scheduled_status_delete(self, id): 499 def scheduled_status_delete(self, id):
@@ -520,5 +501,4 @@ class Mastodon(Internals):
520 Deletes a scheduled status. 501 Deletes a scheduled status.
521 """ 502 """
522 id = self.__unpack_id(id) 503 id = self.__unpack_id(id)
523 url = '/api/v1/scheduled_statuses/{0}'.format(str(id)) 504 self.__api_request('DELETE', f'/api/v1/scheduled_statuses/{id}')
524 self.__api_request('DELETE', url)
diff --git a/mastodon/streaming_endpoints.py b/mastodon/streaming_endpoints.py
index 9ff72f5..fc705e6 100644
--- a/mastodon/streaming_endpoints.py
+++ b/mastodon/streaming_endpoints.py
@@ -46,7 +46,7 @@ class Mastodon(Internals):
46 base = '/api/v1/streaming/hashtag' 46 base = '/api/v1/streaming/hashtag'
47 if local: 47 if local:
48 base += '/local' 48 base += '/local'
49 return self.__stream("{}?tag={}".format(base, tag), listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) 49 return self.__stream(f"{base}?tag={tag}", listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
50 50
51 @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS) 51 @api_version("2.1.0", "2.1.0", _DICT_VERSION_STATUS)
52 def stream_list(self, id, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC): 52 def stream_list(self, id, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC):
@@ -55,7 +55,7 @@ class Mastodon(Internals):
55 list. 55 list.
56 """ 56 """
57 id = self.__unpack_id(id) 57 id = self.__unpack_id(id)
58 return self.__stream("/api/v1/streaming/list?list={}".format(id), listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec) 58 return self.__stream(f"/api/v1/streaming/list?list={id}", listener, run_async=run_async, timeout=timeout, reconnect_async=reconnect_async, reconnect_async_wait_sec=reconnect_async_wait_sec)
59 59
60 @api_version("2.6.0", "2.6.0", _DICT_VERSION_STATUS) 60 @api_version("2.6.0", "2.6.0", _DICT_VERSION_STATUS)
61 def stream_direct(self, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC): 61 def stream_direct(self, listener, run_async=False, timeout=_DEFAULT_STREAM_TIMEOUT, reconnect_async=False, reconnect_async_wait_sec=_DEFAULT_STREAM_RECONNECT_WAIT_SEC):
diff --git a/mastodon/suggestions.py b/mastodon/suggestions.py
index ab55993..a94204b 100644
--- a/mastodon/suggestions.py
+++ b/mastodon/suggestions.py
@@ -28,5 +28,4 @@ class Mastodon(Internals):
28 Remove the user with the given `account_id` from the follow suggestions. 28 Remove the user with the given `account_id` from the follow suggestions.
29 """ 29 """
30 account_id = self.__unpack_id(account_id) 30 account_id = self.__unpack_id(account_id)
31 url = '/api/v1/suggestions/{0}'.format(str(account_id)) 31 self.__api_request('DELETE', f'/api/v1/suggestions/{account_id}')
32 self.__api_request('DELETE', url) \ No newline at end of file
diff --git a/mastodon/timeline.py b/mastodon/timeline.py
index 04406ed..37790c8 100644
--- a/mastodon/timeline.py
+++ b/mastodon/timeline.py
@@ -50,8 +50,7 @@ class Mastodon(Internals):
50 params_initial['local'] = True 50 params_initial['local'] = True
51 51
52 params = self.__generate_params(params_initial, ['timeline']) 52 params = self.__generate_params(params_initial, ['timeline'])
53 url = '/api/v1/timelines/{0}'.format(timeline) 53 return self.__api_request('GET', f'/api/v1/timelines/{timeline}', params)
54 return self.__api_request('GET', url, params)
55 54
56 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS) 55 @api_version("1.0.0", "3.1.4", _DICT_VERSION_STATUS)
57 def timeline_home(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False): 56 def timeline_home(self, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
@@ -91,7 +90,7 @@ class Mastodon(Internals):
91 if hashtag.startswith("#"): 90 if hashtag.startswith("#"):
92 raise MastodonIllegalArgumentError( 91 raise MastodonIllegalArgumentError(
93 "Hashtag parameter should omit leading #") 92 "Hashtag parameter should omit leading #")
94 return self.timeline('tag/{0}'.format(hashtag), max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote) 93 return self.timeline(f'tag/{hashtag}', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
95 94
96 @api_version("2.1.0", "3.1.4", _DICT_VERSION_STATUS) 95 @api_version("2.1.0", "3.1.4", _DICT_VERSION_STATUS)
97 def timeline_list(self, id, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False): 96 def timeline_list(self, id, max_id=None, min_id=None, since_id=None, limit=None, only_media=False, local=False, remote=False):
@@ -101,5 +100,5 @@ class Mastodon(Internals):
101 Returns a list of :ref:`status dicts <status dicts>`. 100 Returns a list of :ref:`status dicts <status dicts>`.
102 """ 101 """
103 id = self.__unpack_id(id) 102 id = self.__unpack_id(id)
104 return self.timeline('list/{0}'.format(id), max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote) 103 return self.timeline(f'list/{id}', max_id=max_id, min_id=min_id, since_id=since_id, limit=limit, only_media=only_media, local=local, remote=remote)
105 104
diff --git a/mastodon/utility.py b/mastodon/utility.py
index 2510dca..200f5c1 100644
--- a/mastodon/utility.py
+++ b/mastodon/utility.py
@@ -39,14 +39,13 @@ def api_version(created_ver, last_changed_ver, return_value_ver):
39 version = max_version(last_changed_ver, return_value_ver) 39 version = max_version(last_changed_ver, return_value_ver)
40 major, minor, patch = parse_version_string(version) 40 major, minor, patch = parse_version_string(version)
41 if major > self.mastodon_major: 41 if major > self.mastodon_major:
42 raise MastodonVersionError("Version check failed (Need version " + version + ")") 42 raise MastodonVersionError(f"Version check failed (Need version {version})")
43 elif major == self.mastodon_major and minor > self.mastodon_minor: 43 elif major == self.mastodon_major and minor > self.mastodon_minor:
44 raise MastodonVersionError("Version check failed (Need version " + version + ")") 44 raise MastodonVersionError(f"Version check failed (Need version {version})")
45 elif major == self.mastodon_major and minor == self.mastodon_minor and patch > self.mastodon_patch: 45 elif major == self.mastodon_major and minor == self.mastodon_minor and patch > self.mastodon_patch:
46 raise MastodonVersionError("Version check failed (Need version " + version + ", patch is " + str(self.mastodon_patch) + ")") 46 raise MastodonVersionError(f"Version check failed (Need version {version}, patch is {self.mastodon_patch})")
47 return function(self, *args, **kwargs) 47 return function(self, *args, **kwargs)
48 function.__doc__ = function.__doc__ + "\n\n *Added: Mastodon v" + \ 48 function.__doc__ += f"\n\n *Added: Mastodon v{created_ver}, last changed: Mastodon v{last_changed_ver}*"
49 created_ver + ", last changed: Mastodon v" + last_changed_ver + "*"
50 return decorate(function, wrapper) 49 return decorate(function, wrapper)
51 return api_min_version_decorator 50 return api_min_version_decorator
52 51
@@ -59,7 +58,7 @@ class AttribAccessDict(dict):
59 if attr in self: 58 if attr in self:
60 return self[attr] 59 return self[attr]
61 else: 60 else:
62 raise AttributeError("Attribute not found: " + str(attr)) 61 raise AttributeError(f"Attribute not found: {attr}")
63 62
64 def __setattr__(self, attr, val): 63 def __setattr__(self, attr, val):
65 if attr in self: 64 if attr in self:
@@ -76,7 +75,7 @@ class AttribAccessList(list):
76 if attr in self: 75 if attr in self:
77 return self[attr] 76 return self[attr]
78 else: 77 else:
79 raise AttributeError("Attribute not found: " + str(attr)) 78 raise AttributeError(f"Attribute not found: {attr}")
80 79
81 def __setattr__(self, attr, val): 80 def __setattr__(self, attr, val):
82 if attr in self: 81 if attr in self:
Powered by cgit v1.2.3 (git 2.41.0)