aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhalcy <halcy@ARARAGI-KUN>2022-11-19 02:40:32 +0200
committerhalcy <halcy@ARARAGI-KUN>2022-11-19 02:40:32 +0200
commitbc2cb5e892f65f39b51b64b70a5893b9232f436d (patch)
tree848bba549efbb0e8e63bdaf1fd19ccea2e9c2b64 /mastodon
parent853cd82ecb9e1d25f395514b3bb1616071d43493 (diff)
downloadmastodon.py-bc2cb5e892f65f39b51b64b70a5893b9232f436d.tar.gz
fix versioning for limited federation instances
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index ae560c5..70aac20 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -454,14 +454,14 @@ class Mastodon:
454 self.mastodon_major = 1 454 self.mastodon_major = 1
455 self.mastodon_minor = 0 455 self.mastodon_minor = 0
456 self.mastodon_patch = 0 456 self.mastodon_patch = 0
457 self.version_check_worked = None
457 458
458 # Versioning 459 # Versioning
459 if mastodon_version == None and self.version_check_mode != 'none': 460 if mastodon_version == None and self.version_check_mode != 'none':
460 self.retrieve_mastodon_version() 461 self.retrieve_mastodon_version()
461 elif self.version_check_mode != 'none': 462 elif self.version_check_mode != 'none':
462 try: 463 try:
463 self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string( 464 self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(mastodon_version)
464 mastodon_version)
465 except: 465 except:
466 raise MastodonVersionError("Bad version specified") 466 raise MastodonVersionError("Bad version specified")
467 467
@@ -477,9 +477,11 @@ class Mastodon:
477 """ 477 """
478 try: 478 try:
479 version_str = self.__instance()["version"].split('+')[0] 479 version_str = self.__instance()["version"].split('+')[0]
480 self.version_check_worked = True
480 except: 481 except:
481 # instance() was added in 1.1.0, so our best guess is 1.0.0. 482 # instance() was added in 1.1.0, so our best guess is 1.0.0.
482 version_str = "1.0.0" 483 version_str = "1.0.0"
484 self.version_check_worked = False
483 485
484 self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(version_str) 486 self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(version_str)
485 return version_str 487 return version_str
@@ -585,20 +587,16 @@ class Mastodon:
585 Returns the access token as a string. 587 Returns the access token as a string.
586 """ 588 """
587 if username is not None and password is not None: 589 if username is not None and password is not None:
588 params = self.__generate_params( 590 params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token'])
589 locals(), ['scopes', 'to_file', 'code', 'refresh_token'])
590 params['grant_type'] = 'password' 591 params['grant_type'] = 'password'
591 elif code is not None: 592 elif code is not None:
592 params = self.__generate_params( 593 params = self.__generate_params(locals(), ['scopes', 'to_file', 'username', 'password', 'refresh_token'])
593 locals(), ['scopes', 'to_file', 'username', 'password', 'refresh_token'])
594 params['grant_type'] = 'authorization_code' 594 params['grant_type'] = 'authorization_code'
595 elif refresh_token is not None: 595 elif refresh_token is not None:
596 params = self.__generate_params( 596 params = self.__generate_params(locals(), ['scopes', 'to_file', 'username', 'password', 'code'])
597 locals(), ['scopes', 'to_file', 'username', 'password', 'code'])
598 params['grant_type'] = 'refresh_token' 597 params['grant_type'] = 'refresh_token'
599 else: 598 else:
600 raise MastodonIllegalArgumentError( 599 raise MastodonIllegalArgumentError('Invalid arguments given. username and password or code are required.')
601 'Invalid arguments given. username and password or code are required.')
602 600
603 params['client_id'] = self.client_id 601 params['client_id'] = self.client_id
604 params['client_secret'] = self.client_secret 602 params['client_secret'] = self.client_secret
@@ -611,11 +609,9 @@ class Mastodon:
611 self.__set_token_expired(int(response.get('expires_in', 0))) 609 self.__set_token_expired(int(response.get('expires_in', 0)))
612 except Exception as e: 610 except Exception as e:
613 if username is not None or password is not None: 611 if username is not None or password is not None:
614 raise MastodonIllegalArgumentError( 612 raise MastodonIllegalArgumentError('Invalid user name, password, or redirect_uris: %s' % e)
615 'Invalid user name, password, or redirect_uris: %s' % e)
616 elif code is not None: 613 elif code is not None:
617 raise MastodonIllegalArgumentError( 614 raise MastodonIllegalArgumentError('Invalid access token or redirect_uris: %s' % e)
618 'Invalid access token or redirect_uris: %s' % e)
619 else: 615 else:
620 raise MastodonIllegalArgumentError('Invalid request: %s' % e) 616 raise MastodonIllegalArgumentError('Invalid request: %s' % e)
621 617
@@ -635,6 +631,10 @@ class Mastodon:
635 631
636 self.__logged_in_id = None 632 self.__logged_in_id = None
637 633
634 # Retry version check if needed (might be required in limited federation mode)
635 if self.version_check_worked == False:
636 self.retrieve_mastodon_version()
637
638 return response['access_token'] 638 return response['access_token']
639 639
640 640
@@ -1427,8 +1427,7 @@ class Mastodon:
1427 """ 1427 """
1428 if not account_id is None or not offset is None or not min_id is None or not max_id is None: 1428 if not account_id is None or not offset is None or not min_id is None or not max_id is None:
1429 if self.verify_minimum_version("2.8.0", cached=True) == False: 1429 if self.verify_minimum_version("2.8.0", cached=True) == False:
1430 raise MastodonVersionError( 1430 raise MastodonVersionError("Advanced search parameters require Mastodon 2.8.0+")
1431 "Advanced search parameters require Mastodon 2.8.0+")
1432 1431
1433 @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT) 1432 @api_version("1.1.0", "2.8.0", __DICT_VERSION_SEARCHRESULT)
1434 def search(self, q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None, exclude_unreviewed=True): 1433 def search(self, q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None, exclude_unreviewed=True):
@@ -1457,8 +1456,7 @@ class Mastodon:
1457 Returns a `search result dict`_, with tags as `hashtag dicts`_. 1456 Returns a `search result dict`_, with tags as `hashtag dicts`_.
1458 """ 1457 """
1459 if self.verify_minimum_version("2.4.1", cached=True) == True: 1458 if self.verify_minimum_version("2.4.1", cached=True) == True:
1460 return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, 1459 return self.search_v2(q, resolve=resolve, result_type=result_type, account_id=account_id, offset=offset, min_id=min_id, max_id=max_id)
1461 offset=offset, min_id=min_id, max_id=max_id)
1462 else: 1460 else:
1463 self.__ensure_search_params_acceptable( 1461 self.__ensure_search_params_acceptable(
1464 account_id, offset, min_id, max_id) 1462 account_id, offset, min_id, max_id)
Powered by cgit v1.2.3 (git 2.41.0)