kopia lustrzana https://github.com/halcy/Mastodon.py
expose deprecation header, fix CI
rodzic
a1a0b4e306
commit
0f94231300
|
@ -19,6 +19,7 @@ v2.1.0 (IN PROGRESS)
|
||||||
* Add status length counter `get_status_length` (Thanks @yuletide for the suggestion and @cheeaun for the assistance)
|
* Add status length counter `get_status_length` (Thanks @yuletide for the suggestion and @cheeaun for the assistance)
|
||||||
* Fix `notifications` returning nonsense when passing a single `id` (Thanks @chinchalinchin for the report)
|
* Fix `notifications` returning nonsense when passing a single `id` (Thanks @chinchalinchin for the report)
|
||||||
* Fix `moved` accidentally being named `moved_to_account` (Thanks @unusualevent for the report)
|
* Fix `moved` accidentally being named `moved_to_account` (Thanks @unusualevent for the report)
|
||||||
|
* Added a warning for deprecated endpoints if the "deprecation" header is present
|
||||||
|
|
||||||
v2.0.1
|
v2.0.1
|
||||||
------
|
------
|
||||||
|
|
6
TODO.md
6
TODO.md
|
@ -4,7 +4,7 @@ Refer to mastodon changelog and API docs for details when implementing, add or m
|
||||||
|
|
||||||
4.4.0 TODOs
|
4.4.0 TODOs
|
||||||
-----------
|
-----------
|
||||||
* [ ] Fix all the issues
|
* [x] Fix all the issues
|
||||||
* [ ] New endpoints for endorsements, replacing "pin" api, which is now deprecated: accounts_endorsements(id), account_endorse(id), account_unendorse(id)
|
* [ ] New endpoints for endorsements, replacing "pin" api, which is now deprecated: accounts_endorsements(id), account_endorse(id), account_unendorse(id)
|
||||||
* [ ] New endpoints for featured tags: tag_feature(name), tag_unfeature(name)
|
* [ ] New endpoints for featured tags: tag_feature(name), tag_unfeature(name)
|
||||||
* [ ] New endpoint: instance_terms, with or without date (format?)
|
* [ ] New endpoint: instance_terms, with or without date (format?)
|
||||||
|
@ -13,8 +13,8 @@ Refer to mastodon changelog and API docs for details when implementing, add or m
|
||||||
* [ ] push_subscribe now has a "standard" parameter to switch between two versions. may also need to update crypto impls?
|
* [ ] push_subscribe now has a "standard" parameter to switch between two versions. may also need to update crypto impls?
|
||||||
* [ ] account_register now has a date of birth param (as above: format?)
|
* [ ] account_register now has a date of birth param (as above: format?)
|
||||||
* [ ] update_credentials now has an attribution_domains param for link attribution (list)
|
* [ ] update_credentials now has an attribution_domains param for link attribution (list)
|
||||||
* [ ] Various updates to return values (automatable, hopefully, other than docs)
|
* [x] Various updates to return values (automatable, hopefully, other than docs)
|
||||||
* [ ] There is a "Deprecation" http header now, expose that to users?
|
* [x] There is a "Deprecation" http header now, expose that to users?
|
||||||
|
|
||||||
General improvements that would be good to do before doing another release
|
General improvements that would be good to do before doing another release
|
||||||
--------------------------------------------------------------------------
|
--------------------------------------------------------------------------
|
||||||
|
|
|
@ -88,3 +88,13 @@ class MastodonRatelimitError(MastodonError):
|
||||||
class MastodonMalformedEventError(MastodonError):
|
class MastodonMalformedEventError(MastodonError):
|
||||||
"""Raised when the server-sent event stream is malformed"""
|
"""Raised when the server-sent event stream is malformed"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Warnings
|
||||||
|
class MastodonWarning(Warning):
|
||||||
|
"""Base class for Mastodon.py warnings"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MastodonDeprecationWarning(MastodonWarning):
|
||||||
|
"""Raised when a deprecated feature is used"""
|
||||||
|
pass
|
|
@ -14,11 +14,12 @@ import collections
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import inspect
|
import inspect
|
||||||
|
import warnings
|
||||||
|
|
||||||
from mastodon.versions import parse_version_string
|
from mastodon.versions import parse_version_string
|
||||||
from mastodon.errors import MastodonNetworkError, MastodonIllegalArgumentError, MastodonRatelimitError, MastodonNotFoundError, \
|
from mastodon.errors import MastodonNetworkError, MastodonIllegalArgumentError, MastodonRatelimitError, MastodonNotFoundError, \
|
||||||
MastodonUnauthorizedError, MastodonInternalServerError, MastodonBadGatewayError, MastodonServiceUnavailableError, \
|
MastodonUnauthorizedError, MastodonInternalServerError, MastodonBadGatewayError, MastodonServiceUnavailableError, \
|
||||||
MastodonGatewayTimeoutError, MastodonServerError, MastodonAPIError, MastodonMalformedEventError
|
MastodonGatewayTimeoutError, MastodonServerError, MastodonAPIError, MastodonMalformedEventError, MastodonDeprecationWarning
|
||||||
from mastodon.compat import urlparse, magic, PurePath, Path
|
from mastodon.compat import urlparse, magic, PurePath, Path
|
||||||
from mastodon.defaults import _DEFAULT_STREAM_TIMEOUT, _DEFAULT_STREAM_RECONNECT_WAIT_SEC
|
from mastodon.defaults import _DEFAULT_STREAM_TIMEOUT, _DEFAULT_STREAM_RECONNECT_WAIT_SEC
|
||||||
from mastodon.return_types import AttribAccessDict, PaginatableList, try_cast_recurse
|
from mastodon.return_types import AttribAccessDict, PaginatableList, try_cast_recurse
|
||||||
|
@ -182,6 +183,10 @@ class Mastodon():
|
||||||
if response_object is None:
|
if response_object is None:
|
||||||
raise MastodonIllegalArgumentError("Illegal request.")
|
raise MastodonIllegalArgumentError("Illegal request.")
|
||||||
|
|
||||||
|
# Is there a "deprecation" header present?
|
||||||
|
if 'deprecation' in response_object.headers:
|
||||||
|
warnings.warn("Endpoint " + endpoint + " is marked as deprecated and may be removed in future Mastodon versions.", MastodonDeprecationWarning)
|
||||||
|
|
||||||
# Parse rate limiting headers
|
# Parse rate limiting headers
|
||||||
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
||||||
self.ratelimit_remaining = int(
|
self.ratelimit_remaining = int(
|
||||||
|
|
|
@ -298,6 +298,8 @@ def try_cast(t, value, retry = True, union_specializer = None):
|
||||||
value = t(**value)
|
value = t(**value)
|
||||||
|
|
||||||
# Did we have type arguments on the dict? If so, we need to try to cast the values
|
# Did we have type arguments on the dict? If so, we need to try to cast the values
|
||||||
|
# This will not work in 3.7 and 3.8, which is unfortunate, but them's the breaks of using
|
||||||
|
# very old versions.
|
||||||
if hasattr(t, '__args__') and len(t.__args__) > 1:
|
if hasattr(t, '__args__') and len(t.__args__) > 1:
|
||||||
value_cast_type = t.__args__[1]
|
value_cast_type = t.__args__[1]
|
||||||
for key, val in value.items():
|
for key, val in value.items():
|
||||||
|
|
Plik diff jest za duży
Load Diff
|
@ -911,8 +911,9 @@ def test_entity_instanceusageusers(mastodon_base, mastodon_admin):
|
||||||
def test_entity_ruletranslation(mastodon_base, mastodon_admin):
|
def test_entity_ruletranslation(mastodon_base, mastodon_admin):
|
||||||
mastodon = mastodon_base
|
mastodon = mastodon_base
|
||||||
result = mastodon.instance().rules[0].translations['de']
|
result = mastodon.instance().rules[0].translations['de']
|
||||||
assert real_issubclass(type(result), RuleTranslation), str(type(result)) + ' is not a subclass of RuleTranslation'
|
if sys.version_info >= (3, 9):
|
||||||
result = Entity.from_json(result.to_json())
|
assert real_issubclass(type(result), RuleTranslation), str(type(result)) + ' is not a subclass of RuleTranslation'
|
||||||
|
result = Entity.from_json(result.to_json())
|
||||||
if sys.version_info >= (3, 9):
|
if sys.version_info >= (3, 9):
|
||||||
assert real_issubclass(type(result), RuleTranslation), str(type(result)) + ' is not a subclass of RuleTranslation after to_json/from_json'
|
assert real_issubclass(type(result), RuleTranslation), str(type(result)) + ' is not a subclass of RuleTranslation after to_json/from_json'
|
||||||
|
|
||||||
|
@ -928,8 +929,9 @@ def test_entity_ruletranslation(mastodon_base, mastodon_admin):
|
||||||
def test_entity_rule(mastodon_base, mastodon_admin):
|
def test_entity_rule(mastodon_base, mastodon_admin):
|
||||||
mastodon = mastodon_base
|
mastodon = mastodon_base
|
||||||
result = mastodon.instance().rules[0]
|
result = mastodon.instance().rules[0]
|
||||||
assert real_issubclass(type(result), Rule), str(type(result)) + ' is not a subclass of Rule'
|
if sys.version_info >= (3, 9):
|
||||||
result = Entity.from_json(result.to_json())
|
assert real_issubclass(type(result), Rule), str(type(result)) + ' is not a subclass of Rule'
|
||||||
|
result = Entity.from_json(result.to_json())
|
||||||
if sys.version_info >= (3, 9):
|
if sys.version_info >= (3, 9):
|
||||||
assert real_issubclass(type(result), Rule), str(type(result)) + ' is not a subclass of Rule after to_json/from_json'
|
assert real_issubclass(type(result), Rule), str(type(result)) + ' is not a subclass of Rule after to_json/from_json'
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue