aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhalcy <halcy@ARARAGI-KUN>2022-11-24 01:37:47 +0200
committerhalcy <halcy@ARARAGI-KUN>2022-11-24 01:37:47 +0200
commit3caa27a113945bc1662f4f63fa0387b9aece6390 (patch)
tree714364c68062192a26a55d5db999e3e5ee81c95d /mastodon
parentb7266db01b73348bb74dd4277053825580193477 (diff)
downloadmastodon.py-3caa27a113945bc1662f4f63fa0387b9aece6390.tar.gz
Robustify version parsing
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 896d87d..d98289d 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -470,6 +470,17 @@ class Mastodon:
470 if ratelimit_method not in ["throw", "wait", "pace"]: 470 if ratelimit_method not in ["throw", "wait", "pace"]:
471 raise MastodonIllegalArgumentError("Invalid ratelimit method.") 471 raise MastodonIllegalArgumentError("Invalid ratelimit method.")
472 472
473 def __normalize_version_string(self, version_string):
474 # Split off everything after the first space, to take care of Pleromalikes so that the parser doesn't get confused in case those have a + somewhere in their version
475 version_string = version_string.split(" ")[0]
476 try:
477 # Attempt to split at + and check if the part after parses as a version string, to account for hometown
478 parse_version_string(version_string.split("+")[1])
479 return version_string.split("+")[1]
480 except:
481 # If this fails, assume that if there is a +, what is before that is the masto version (or that there is no +)
482 return version_string.split("+")[0]
483
473 def retrieve_mastodon_version(self): 484 def retrieve_mastodon_version(self):
474 """ 485 """
475 Determine installed Mastodon version and set major, minor and patch (not including RC info) accordingly. 486 Determine installed Mastodon version and set major, minor and patch (not including RC info) accordingly.
@@ -477,7 +488,7 @@ class Mastodon:
477 Returns the version string, possibly including rc info. 488 Returns the version string, possibly including rc info.
478 """ 489 """
479 try: 490 try:
480 version_str = self.__instance()["version"].split('+')[0] 491 version_str = self.__normalize_version_string(self.__instance()["version"])
481 self.version_check_worked = True 492 self.version_check_worked = True
482 except: 493 except:
483 # instance() was added in 1.1.0, so our best guess is 1.0.0. 494 # instance() was added in 1.1.0, so our best guess is 1.0.0.
Powered by cgit v1.2.3 (git 2.41.0)