From 3caa27a113945bc1662f4f63fa0387b9aece6390 Mon Sep 17 00:00:00 2001 From: halcy Date: Thu, 24 Nov 2022 01:37:47 +0200 Subject: Robustify version parsing --- mastodon/Mastodon.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'mastodon') 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: if ratelimit_method not in ["throw", "wait", "pace"]: raise MastodonIllegalArgumentError("Invalid ratelimit method.") + def __normalize_version_string(self, version_string): + # 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 + version_string = version_string.split(" ")[0] + try: + # Attempt to split at + and check if the part after parses as a version string, to account for hometown + parse_version_string(version_string.split("+")[1]) + return version_string.split("+")[1] + except: + # If this fails, assume that if there is a +, what is before that is the masto version (or that there is no +) + return version_string.split("+")[0] + def retrieve_mastodon_version(self): """ Determine installed Mastodon version and set major, minor and patch (not including RC info) accordingly. @@ -477,7 +488,7 @@ class Mastodon: Returns the version string, possibly including rc info. """ try: - version_str = self.__instance()["version"].split('+')[0] + version_str = self.__normalize_version_string(self.__instance()["version"]) self.version_check_worked = True except: # instance() was added in 1.1.0, so our best guess is 1.0.0. -- cgit v1.2.3