diff options
-rw-r--r-- | CHANGELOG.rst | 19 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 13 | ||||
-rw-r--r-- | tests/test_instance.py | 13 |
3 files changed, 35 insertions, 10 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index bc84eea..3079108 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst | |||
@@ -4,17 +4,18 @@ version number. Breaking changes will be indicated by a change in the minor | |||
4 | 4 | ||
5 | v1.7.0 | 5 | v1.7.0 |
6 | ------ | 6 | ------ |
7 | * Clean code up a bit (thanks eumiro) | 7 | * Cleaned code up a bit (thanks eumiro) |
8 | * Fix some Pleroma related issues (thanks aveao, taraletti, adbenitez) | 8 | * Fixed some Pleroma related issues (thanks aveao, taraletti, adbenitez) |
9 | * Add post editing (`status_update`, `status_source`, `status_history`) | 9 | * Added post editing (`status_update`, `status_source`, `status_history`) |
10 | * Add missing streaming events | 10 | * Added missing streaming events |
11 | * Add missing parameters on directory endpoint (thanks heharkon) | 11 | * Added missing parameters on directory endpoint (thanks heharkon) |
12 | * This isn't somehing I changed but thank you a / triggerofsol for answering Many questions I had about specifics of what the API does that are not documented | 12 | * This isn't somehing I changed but thank you a / triggerofsol for answering Many questions I had about specifics of what the API does that are not documented |
13 | * Fixed search ignoring `exclude_unreviewed` (Thanks acidghost) | 13 | * Fixed search ignoring `exclude_unreviewed` (Thanks acidghost) |
14 | * Add support for using pathlib paths when loading media files (Thanks reagle) | 14 | * Added support for using pathlib paths when loading media files (Thanks reagle) |
15 | * Remove blocklist with long dead instances | 15 | * Removed blocklist with long dead instances |
16 | * Add `types` parameter to notifications. | 16 | * Added `types` parameter to notifications. |
17 | * Document additional notification types | 17 | * Documented additional notification types |
18 | * Made version parsing more robust against varions things that Mastodon-compatible APIs might throw at it. | ||
18 | * TECHNICALLY BREAKING CHANGE, but I would be quite surprised if this actually breaks anyone: Date parsing will now, when the date string is empty, return Jan. 1st, 1970 instead. This is to work around what I assume is a bug in Pleroma. | 19 | * TECHNICALLY BREAKING CHANGE, but I would be quite surprised if this actually breaks anyone: Date parsing will now, when the date string is empty, return Jan. 1st, 1970 instead. This is to work around what I assume is a bug in Pleroma. |
19 | 20 | ||
20 | v1.6.3 | 21 | v1.6.3 |
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. |
diff --git a/tests/test_instance.py b/tests/test_instance.py index 1fbd692..e25a686 100644 --- a/tests/test_instance.py +++ b/tests/test_instance.py | |||
@@ -1,6 +1,7 @@ | |||
1 | import pytest | 1 | import pytest |
2 | 2 | ||
3 | from mastodon.Mastodon import MastodonVersionError | 3 | from mastodon.Mastodon import MastodonVersionError |
4 | from mastodon.Mastodon import parse_version_string | ||
4 | import datetime | 5 | import datetime |
5 | import os | 6 | import os |
6 | import pickle | 7 | import pickle |
@@ -75,3 +76,15 @@ def test_directory(api): | |||
75 | @pytest.mark.vcr() | 76 | @pytest.mark.vcr() |
76 | def test_instance_rules(api): | 77 | def test_instance_rules(api): |
77 | assert isinstance(api.instance_rules(), list) | 78 | assert isinstance(api.instance_rules(), list) |
79 | |||
80 | def test_version_parsing(api): | ||
81 | assert parse_version_string(api._Mastodon__normalize_version_string("4.0.2")) == [4, 0, 2] | ||
82 | assert parse_version_string(api._Mastodon__normalize_version_string("2.1.0rc3")) == [2, 1, 0] | ||
83 | assert parse_version_string(api._Mastodon__normalize_version_string("1.0.7+3.5.5")) == [3, 5, 5] | ||
84 | assert parse_version_string(api._Mastodon__normalize_version_string("1.0.7+3.5.5rc2")) == [3, 5, 5] | ||
85 | assert parse_version_string(api._Mastodon__normalize_version_string("3.5.1+chitter")) == [3, 5, 1] | ||
86 | assert parse_version_string(api._Mastodon__normalize_version_string("3.5.1+chitter-6.6.6")) == [3, 5, 1] | ||
87 | assert parse_version_string(api._Mastodon__normalize_version_string("3.5.1rc4+chitter-6.6.6")) == [3, 5, 1] | ||
88 | assert parse_version_string(api._Mastodon__normalize_version_string("3.5.1+chitter6.6.6")) == [3, 5, 1] | ||
89 | assert parse_version_string(api._Mastodon__normalize_version_string("3.5.0 (compatible; Pleroma 1.2.3)")) == [3, 5, 0] | ||
90 | assert parse_version_string(api._Mastodon__normalize_version_string("3.2.1rc3 (compatible; Akkoma 3.2.4+shinychariot)")) == [3, 2, 1] | ||