a bunch of fixes to entities and typing, pre starting to merge some PRs

pull/391/head
halcy 2024-12-01 14:56:08 +02:00
rodzic 47aa316c36
commit 9ba51c42fa
8 zmienionych plików z 1270 dodań i 178 usunięć

Wyświetl plik

@ -75,17 +75,14 @@ class Mastodon(Internals):
raise MastodonIllegalArgumentError(f'Invalid request during oauth phase: {e}') raise MastodonIllegalArgumentError(f'Invalid request during oauth phase: {e}')
# Step 2: Use that to create a user # Step 2: Use that to create a user
try: response = self.__api_request('POST', '/api/v1/accounts', params, do_ratelimiting=False, access_token_override=temp_access_token, skip_error_check=True, override_type=dict)
response = self.__api_request('POST', '/api/v1/accounts', params, do_ratelimiting=False, access_token_override=temp_access_token, skip_error_check=True, override_type=dict) if "error" in response:
if "error" in response: if return_detailed_error:
if return_detailed_error: return None, try_cast(AccountCreationError, response)
return None, try_cast(AccountCreationError, response) raise MastodonIllegalArgumentError(f'Invalid request: {response["error"]}')
raise MastodonIllegalArgumentError(f'Invalid request: {response["error"]}') self.access_token = response['access_token']
self.access_token = response['access_token'] self.__set_refresh_token(response.get('refresh_token'))
self.__set_refresh_token(response.get('refresh_token')) self.__set_token_expired(int(response.get('expires_in', 0)))
self.__set_token_expired(int(response.get('expires_in', 0)))
except Exception as e:
raise MastodonIllegalArgumentError('Invalid request')
# Step 3: Check scopes, persist, et cetera # Step 3: Check scopes, persist, et cetera
received_scopes = response["scope"].split(" ") received_scopes = response["scope"].split(" ")

Wyświetl plik

@ -361,10 +361,7 @@ class Mastodon(Internals):
assert self.client_id is not None and isinstance(self.client_id, str) assert self.client_id is not None and isinstance(self.client_id, str)
assert self.client_secret is not None assert self.client_secret is not None
with open(str(to_file), 'w') as token_file: with open(str(to_file), 'w') as token_file:
token_file.write(response['access_token'] + "\n") token_file.write(self.persistable_login_credentials())
token_file.write(self.api_base_url + "\n")
token_file.write(self.client_id + "\n")
token_file.write(self.client_secret + "\n")
self.__logged_in_id = None self.__logged_in_id = None
# Retry version check if needed (might be required in limited federation mode) # Retry version check if needed (might be required in limited federation mode)
@ -372,6 +369,18 @@ class Mastodon(Internals):
self.retrieve_mastodon_version() self.retrieve_mastodon_version()
return response['access_token'] return response['access_token']
def persistable_login_credentials(self):
"""
Return a string (which you should treat as opaque) that can be passed to :ref:`log_in()` to get an authenticated API object with the same access as this one.
This is the same thing that would be written to a file by :ref:`log_in() <log_in()>` with the `to_file` parameter.
"""
if self.access_token is None:
raise MastodonIllegalArgumentError("Not logged in, do not have a token to persist.")
if self.client_id is None or self.client_secret is None or not isinstance(self.client_id, str):
raise MastodonIllegalArgumentError("Client authentication (id + secret) is required to persist tokens.")
return self.access_token + "\n" + self.api_base_url + "\n" + self.client_id + "\n" + self.client_secret + "\n"
def revoke_access_token(self): def revoke_access_token(self):
""" """

Wyświetl plik

@ -13,7 +13,7 @@ class Mastodon(Internals):
# Reading data: Featured hashtags # Reading data: Featured hashtags
### ###
@api_version("3.0.0", "3.0.0", _DICT_VERSION_FEATURED_TAG) @api_version("3.0.0", "3.0.0", _DICT_VERSION_FEATURED_TAG)
def featured_tags(self) -> NonPaginatableList[Tag]: def featured_tags(self) -> NonPaginatableList[FeaturedTag]:
""" """
Return the hashtags the logged-in user has set to be featured on Return the hashtags the logged-in user has set to be featured on
their profile as a list of :ref:`featured tag dicts <featured tag dicts>`. their profile as a list of :ref:`featured tag dicts <featured tag dicts>`.
@ -21,7 +21,7 @@ class Mastodon(Internals):
return self.__api_request('GET', '/api/v1/featured_tags') return self.__api_request('GET', '/api/v1/featured_tags')
@api_version("3.0.0", "3.0.0", _DICT_VERSION_HASHTAG) @api_version("3.0.0", "3.0.0", _DICT_VERSION_HASHTAG)
def featured_tag_suggestions(self) -> NonPaginatableList[Tag]: def featured_tag_suggestions(self) -> NonPaginatableList[FeaturedTag]:
""" """
Returns the logged-in user's 10 most commonly-used hashtags. Returns the logged-in user's 10 most commonly-used hashtags.
""" """

Wyświetl plik

@ -10,7 +10,7 @@ from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals from mastodon.internals import Mastodon as Internals
from mastodon.types import Status, IdType, ScheduledStatus, PreviewCard, Context, NonPaginatableList, Account,\ from mastodon.types import Status, IdType, ScheduledStatus, PreviewCard, Context, NonPaginatableList, Account,\
MediaAttachment, Poll, StatusSource, PaginatableList MediaAttachment, Poll, StatusSource, StatusEdit, PaginatableList
from typing import Union, Optional, List from typing import Union, Optional, List
@ -295,9 +295,9 @@ class Mastodon(Internals):
) )
@api_version("3.5.0", "3.5.0", _DICT_VERSION_STATUS_EDIT) @api_version("3.5.0", "3.5.0", _DICT_VERSION_STATUS_EDIT)
def status_history(self, id: Union[Status, IdType]) -> NonPaginatableList[Status]: def status_history(self, id: Union[StatusEdit, IdType]) -> NonPaginatableList[StatusEdit]:
""" """
Returns the edit history of a status as a list of Status objects, starting Returns the edit history of a status as a list of StatusEdit objects, starting
from the original form. Note that this means that a status that has been edited from the original form. Note that this means that a status that has been edited
once will have *two* entries in this list, a status that has been edited twice once will have *two* entries in this list, a status that has been edited twice
will have three, and so on. will have three, and so on.

Wyświetl plik

@ -117,6 +117,15 @@ class Account(AttribAccessDict):
* 0.1.0: added * 0.1.0: added
""" """
uri: "str"
"""
Webfinger-resolvable URI for this account.
Should contain (as text): URL
Version history:
* 4.2.0: added
"""
avatar: "str" avatar: "str"
""" """
URL for this users avatar, can be animated. URL for this users avatar, can be animated.
@ -218,11 +227,11 @@ class Account(AttribAccessDict):
* 4.0.0: added * 4.0.0: added
""" """
roles: "EntityList" roles: "Optional[EntityList]"
""" """
THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT. THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT.
Deprecated. Was a list of strings with the users roles. Now just an empty list. Mastodon.py makes no attempt to fill it, and the field may be removed if Mastodon removes it. Use the `role` field instead. Deprecated. Was a list of strings with the users roles. Now just an empty list. Mastodon.py makes no attempt to fill it, and the field may be removed if Mastodon removes it. Use the `role` field instead. (optional, nullable)
Version history: Version history:
* 0.1.0: added * 0.1.0: added
@ -253,7 +262,23 @@ class Account(AttribAccessDict):
* 3.3.0: added * 3.3.0: added
""" """
_version = "4.0.0" indexable: "bool"
"""
Boolean indicating whether public posts by this account should be searchable by anyone.
Version history:
* 4.2.0: added
"""
hide_collections: "bool"
"""
Boolean indicating whether a user has chosen to hide their network (followers/followed accounts).
Version history:
* 4.1.0: added
"""
_version = "4.2.0"
class AccountField(AttribAccessDict): class AccountField(AttribAccessDict):
""" """
@ -368,9 +393,9 @@ class CredentialAccountSource(AttribAccessDict):
* 1.5.0: added * 1.5.0: added
""" """
language: "str" language: "Optional[str]"
""" """
The default posting language for new statuses. The default posting language for new statuses. (nullable)
Should contain (as text): TwoLetterLanguageCodeEnum Should contain (as text): TwoLetterLanguageCodeEnum
Version history: Version history:
@ -393,7 +418,31 @@ class CredentialAccountSource(AttribAccessDict):
* 3.0.0: added * 3.0.0: added
""" """
_version = "3.0.0" indexable: "bool"
"""
Boolean indicating whether public posts by this user should be searchable by anyone.
Version history:
* 4.2.0: added
"""
hide_collections: "bool"
"""
Boolean indicating whether the user has chosen to hide their network (followers/followed accounts).
Version history:
* 4.1.0: added
"""
discoverable: "Optional[bool]"
"""
Indicates whether or not the user is visible on the discovery page. (nullable)
Version history:
* 3.1.0: added
"""
_version = "4.2.0"
class Status(AttribAccessDict): class Status(AttribAccessDict):
""" """
@ -412,7 +461,7 @@ class Status(AttribAccessDict):
uri: "str" uri: "str"
""" """
Descriptor for the status. Mastodon, for example, may use something like: 'tag:mastodon.social,2016-11-25:objectId=<id>:objectType=Status'. Descriptor for the status EG 'tag:mastodon.social,2016-11-25:objectId=<id>:objectType=Status'.
Version history: Version history:
* 0.1.0: added * 0.1.0: added
@ -533,9 +582,9 @@ class Status(AttribAccessDict):
* 0.9.9: added * 0.9.9: added
""" """
mentions: "EntityList[Account]" mentions: "EntityList[StatusMention]"
""" """
A list Mentions this status includes. A list of StatusMention this status includes.
Version history: Version history:
* 0.6.0: added * 0.6.0: added
@ -711,9 +760,9 @@ class StatusEdit(AttribAccessDict):
* 3.5.0: added * 3.5.0: added
""" """
poll: "Poll" poll: "Optional[Poll]"
""" """
The current state of the poll options at this revision. Note that edits changing the poll options will be collapsed together into one edit, since this action resets the poll. The current state of the poll options at this revision. Note that edits changing the poll options will be collapsed together into one edit, since this action resets the poll. (optional)
Version history: Version history:
* 3.5.0: added * 3.5.0: added
@ -876,9 +925,9 @@ class ScheduledStatusParams(AttribAccessDict):
* 2.7.0: added * 2.7.0: added
""" """
visibility: "str" visibility: "Optional[str]"
""" """
Visibility of the status. Visibility of the status. (nullable)
Version history: Version history:
* 2.7.0: added * 2.7.0: added
@ -1223,9 +1272,9 @@ class CustomEmoji(AttribAccessDict):
* 2.0.0: added * 2.0.0: added
""" """
category: "str" category: "Optional[str]"
""" """
The category to display the emoji under (not present if none is set). The category to display the emoji under (not present if none is set). (nullable)
Version history: Version history:
* 3.0.0: added * 3.0.0: added
@ -1240,6 +1289,14 @@ class Application(AttribAccessDict):
See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/Application/ See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/Application/
""" """
id: "IdType"
"""
ID of the application.
Version history:
* 2.7.0: added
"""
name: "str" name: "str"
""" """
The applications name. The applications name.
@ -1259,13 +1316,45 @@ class Application(AttribAccessDict):
vapid_key: "str" vapid_key: "str"
""" """
THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT.
A vapid key that can be used in web applications. A vapid key that can be used in web applications.
Version history: Version history:
* 2.8.0: added * 2.8.0: added
* 4.3.0: deprecated
""" """
_version = "3.5.1" redirect_uri: "str"
"""
THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT.
The applications redirect URI or urn:ietf:wg:oauth:2.0:oob. Deprecated, it is recommended to use redirect_uris instead.
Version history:
* 0.0.0: added
* 4.3.0: deprecated
"""
redirect_uris: "EntityList[str]"
"""
The applications redirect URI or urn:ietf:wg:oauth:2.0:oob. Deprecated, it is recommended to use redirect_uris instead.
Should contain (as text): URL
Version history:
* 4.3.0: added
"""
scopes: "EntityList[str]"
"""
The applications available scopes.
Should contain (as text): Scopes
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class Relationship(AttribAccessDict): class Relationship(AttribAccessDict):
""" """
@ -1568,15 +1657,24 @@ class Notification(AttribAccessDict):
* 0.9.9: added * 0.9.9: added
""" """
status: "Status" status: "Optional[Status]"
""" """
In case of "mention", the mentioning status In case of reblog / favourite, the reblogged / favourited status. In case of "mention", the mentioning status In case of reblog / favourite, the reblogged / favourited status. (optional)
Version history: Version history:
* 0.9.9: added * 0.9.9: added
* 4.0.0: is now optional
""" """
_version = "4.0.0" group_key: "str"
"""
A key to group notifications by. Structure is unspecified and subject to change, so please do not make assumptions about it.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class Context(AttribAccessDict): class Context(AttribAccessDict):
""" """
@ -1635,7 +1733,15 @@ class UserList(AttribAccessDict):
* 3.3.0: added * 3.3.0: added
""" """
_version = "3.3.0" exclusive: "Optional[bool]"
"""
Boolean indicating whether users on this list are removed from the home feed (appearing exclusively as part of the list). nb: This setting applies to posts at the time they are put into a feed. (optional)
Version history:
* 4.2.0: added
"""
_version = "4.2.0"
class MediaAttachment(AttribAccessDict): class MediaAttachment(AttribAccessDict):
""" """
@ -1679,20 +1785,20 @@ class MediaAttachment(AttribAccessDict):
* 0.6.0: added * 0.6.0: added
""" """
preview_url: "str" preview_url: "Optional[str]"
""" """
The URL for the media preview. The URL for the media preview. (nullable)
Should contain (as text): URL Should contain (as text): URL
Version history: Version history:
* 0.6.0: added * 0.6.0: added
""" """
text_url: "str" text_url: "Optional[str]"
""" """
THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT. THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT.
Deprecated. The display text for the media (what shows up in text). May not be present in mastodon versions after 3.5.0. Deprecated. The display text for the media (what shows up in text). May not be present in mastodon versions after 3.5.0. (optional)
Should contain (as text): URL Should contain (as text): URL
Version history: Version history:
@ -1740,7 +1846,7 @@ class MediaAttachment(AttribAccessDict):
class MediaAttachmentMetadataContainer(AttribAccessDict): class MediaAttachmentMetadataContainer(AttribAccessDict):
""" """
An object holding metadata about a media attachment and its thumbnail. An object holding metadata about a media attachment and its thumbnail. In addition to the documented fields, there may be additional fields. These are not documented, not guaranteed to be present (they are a Mastodon implementation detail), and may change without notice, so relying on them is not recommended.
See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/MediaAttachment/ See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/MediaAttachment/
""" """
@ -1761,17 +1867,17 @@ class MediaAttachmentMetadataContainer(AttribAccessDict):
* 0.6.0: added * 0.6.0: added
""" """
colors: "MediaAttachmentColors" colors: "Optional[MediaAttachmentColors]"
""" """
Information about accent colors for the media. Information about accent colors for the media. (optional)
Version history: Version history:
* 4.0.0: added * 4.0.0: added
""" """
focus: "MediaAttachmentFocusPoint" focus: "Optional[MediaAttachmentFocusPoint]"
""" """
Information about the focus point for the media. Information about the focus point for the media. (optional)
Version history: Version history:
* 3.3.0: added * 3.3.0: added
@ -1822,7 +1928,7 @@ class MediaAttachmentImageMetadata(AttribAccessDict):
class MediaAttachmentVideoMetadata(AttribAccessDict): class MediaAttachmentVideoMetadata(AttribAccessDict):
""" """
Metadata for a video or gifv media attachment. Metadata for a video attachment. This can be a proper video, or a gifv (a looping, soundless animation). Both use the same data model currently, though there is a possibility that they could be split in the future.
See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/MediaAttachment/ See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/MediaAttachment/
""" """
@ -2003,19 +2109,23 @@ class PreviewCard(AttribAccessDict):
author_name: "str" author_name: "str"
""" """
Name of the embedded contents author. THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT.
Name of the embedded contents author. Deprecated in favour of the `authors` field.
Version history: Version history:
* 1.3.0: added * 1.3.0: added
* 4.3.0: deprecated
""" """
author_url: "str" author_url: "str"
""" """
URL pointing to the embedded contents author. URL pointing to the embedded contents author. Deprecated in favour of the `authors` field.
Should contain (as text): URL Should contain (as text): URL
Version history: Version history:
* 1.3.0: added * 1.3.0: added
* 4.3.0: deprecated
""" """
width: "int" width: "int"
@ -2087,7 +2197,67 @@ class PreviewCard(AttribAccessDict):
* 2.1.0: added * 2.1.0: added
""" """
_version = "3.2.0" authors: "EntityList[PreviewCardAuthor]"
"""
List of fediverse accounts of the authors of this post, as `PreviewCardAuthor`.
Version history:
* 4.3.0: added
"""
image_description: "str"
"""
Alt text / image description for the image preview for the card.
Version history:
* 4.2.0: added
"""
published_at: "Optional[datetime]"
"""
Publication time of the embedded content, if available, as a `datetime` object. (nullable)
Version history:
* 4.2.0: added
"""
_version = "4.3.0"
class PreviewCardAuthor(AttribAccessDict):
"""
A preview card attached to a status, e.g. for an embedded video or link.
See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/PreviewCardAuthor/
"""
name: "str"
"""
THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT.
Name of the embedded contents author.
Version history:
* 4.3.0: added
"""
url: "str"
"""
URL pointing to the embedded contents author.
Should contain (as text): URL
Version history:
* 4.3.0: added
"""
account: "Account"
"""
Account of the author of this post, as `Account`.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class Search(AttribAccessDict): class Search(AttribAccessDict):
""" """
@ -2451,12 +2621,12 @@ class InstanceV2(AttribAccessDict):
* 4.0.0: added * 4.0.0: added
""" """
configuration: "InstanceConfiguration" configuration: "InstanceConfigurationV2"
""" """
Various instance configuration settings - especially various limits (character counts, media upload sizes, ...). Various instance configuration settings - especially various limits (character counts, media upload sizes, ...).
Version history: Version history:
* 3.1.4: added * 4.0.0: added
""" """
registrations: "InstanceRegistrations" registrations: "InstanceRegistrations"
@ -2483,7 +2653,50 @@ class InstanceV2(AttribAccessDict):
* 4.0.0: added * 4.0.0: added
""" """
_version = "4.0.0" icon: "EntityList[InstanceIcon]"
"""
The instance icon, as a list of `InstanceIcon`s, with entries representing different available size variants.
Should contain (as text): URL
Version history:
* 4.3.0: added
"""
api_versions: "AttribAccessDict"
"""
A list of API versions supported by this instance, each as an entry in a dict with the name of the implementation as the key (such as 'mastodon'). The exact format is unspecified, any fork or implementation can put what if feels like there. Mastodon currently puts just '2'.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class InstanceIcon(AttribAccessDict):
"""
Icon for the instance, in a specific size.
See also (Mastodon API documentation): https://docs.joinmastodon.org/methods/instance/#InstanceIcon
"""
src: "str"
"""
URL for this icon size.
Should contain (as text): URL
Version history:
* 4.3.0: added
"""
size: "str"
"""
Textual representation of the icon size in pixels as (width)x(height) string, e.g. '64x64'.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class InstanceConfigurationV2(AttribAccessDict): class InstanceConfigurationV2(AttribAccessDict):
""" """
@ -2540,7 +2753,32 @@ class InstanceConfigurationV2(AttribAccessDict):
* 4.0.0: added * 4.0.0: added
""" """
_version = "4.0.0" vapid: "InstanceVapidKey"
"""
VAPID key used by this instance to sign webpush requests. Only present for the v2 API variant of the instance API.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class InstanceVapidKey(AttribAccessDict):
"""
The VAPID key used by this instance to sign webpush requests.
See also (Mastodon API documentation): https://docs.joinmastodon.org/methods/instance/
"""
public_key: "str"
"""
The public key in VAPID format.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class InstanceURLsV2(AttribAccessDict): class InstanceURLsV2(AttribAccessDict):
""" """
@ -2719,13 +2957,21 @@ class Rule(AttribAccessDict):
text: "str" text: "str"
""" """
The rule to be followed. The rule to be followed, in few words.
Version history: Version history:
* 3.4.0: added * 3.4.0: added
""" """
_version = "3.4.0" hint: "str"
"""
Potentially, the rule to be followed, in more words.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class InstanceRegistrations(AttribAccessDict): class InstanceRegistrations(AttribAccessDict):
""" """
@ -2811,7 +3057,15 @@ class InstanceAccountConfiguration(AttribAccessDict):
* 4.0.0: added * 4.0.0: added
""" """
_version = "4.0.0" max_pinned_statuses: "int"
"""
The maximum number of pinned statuses for an account.
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class InstanceStatusConfiguration(AttribAccessDict): class InstanceStatusConfiguration(AttribAccessDict):
""" """
@ -3136,7 +3390,7 @@ class NodeinfoUsageUsers(AttribAccessDict):
class NodeinfoMetadata(AttribAccessDict): class NodeinfoMetadata(AttribAccessDict):
""" """
Nodeinfo extra metadata. Nodeinfo extra metadata. Entirely freeform, be careful about consuming it programatically. Survey of real world usage: https://codeberg.org/thefederationinfo/nodeinfo_metadata_survey.
See also (Mastodon API documentation): https://github.com/jhass/nodeinfo See also (Mastodon API documentation): https://github.com/jhass/nodeinfo
""" """
@ -3378,9 +3632,9 @@ class AdminReport(AttribAccessDict):
* 3.5.0: added * 3.5.0: added
""" """
forwarded: "bool" forwarded: "Optional[bool]"
""" """
Whether a report was forwarded to a remote instance. Whether a report was forwarded to a remote instance. Can be None. (nullable)
Version history: Version history:
* 4.0.0: added * 4.0.0: added
@ -3458,81 +3712,81 @@ class WebPushSubscriptionAlerts(AttribAccessDict):
See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/WebPushSubscription/ See also (Mastodon API documentation): https://docs.joinmastodon.org/entities/WebPushSubscription/
""" """
follow: "bool" follow: "Optional[bool]"
""" """
True if push subscriptions for follow events have been requested, false or not present otherwise. True if push subscriptions for follow events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 2.4.0: added * 2.4.0: added
""" """
favourite: "bool" favourite: "Optional[bool]"
""" """
True if push subscriptions for favourite events have been requested, false or not present otherwise. True if push subscriptions for favourite events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 2.4.0: added * 2.4.0: added
""" """
reblog: "bool" reblog: "Optional[bool]"
""" """
True if push subscriptions for reblog events have been requested, false or not present otherwise. True if push subscriptions for reblog events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 2.4.0: added * 2.4.0: added
""" """
mention: "bool" mention: "Optional[bool]"
""" """
True if push subscriptions for mention events have been requested, false or not present otherwise. True if push subscriptions for mention events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 2.4.0: added * 2.4.0: added
""" """
poll: "bool" poll: "Optional[bool]"
""" """
True if push subscriptions for poll events have been requested, false or not present otherwise. True if push subscriptions for poll events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 2.8.0: added * 2.8.0: added
""" """
follow_request: "bool" follow_request: "Optional[bool]"
""" """
True if push subscriptions for follow request events have been requested, false or not present otherwise. True if push subscriptions for follow request events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 2.4.0: added * 2.4.0: added
""" """
status: "bool" status: "Optional[bool]"
""" """
True if push subscriptions for status creation (watched users only) events have been requested, false or not present otherwise. True if push subscriptions for status creation (watched users only) events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 3.1.0: added * 3.1.0: added
""" """
update: "bool" update: "Optional[bool]"
""" """
True if push subscriptions for status update (edit) events have been requested, false or not present otherwise. True if push subscriptions for status update (edit) events have been requested, false or not present otherwise. (nullable)
Version history: Version history:
* 3.3.0: added * 3.3.0: added
""" """
admin_sign_up: "bool" admin_sign_up: "Optional[bool]"
""" """
True if push subscriptions for sign up events have been requested, false or not present otherwise. Admins only. True if push subscriptions for sign up events have been requested, false or not present otherwise. Admins only. (nullable)
Version history: Version history:
* 3.5.0: added * 3.5.0: added
""" """
admin_report: "bool" admin_report: "Optional[bool]"
""" """
True if push subscriptions for report creation events have been requested, false or not present otherwise. Admins only. True if push subscriptions for report creation events have been requested, false or not present otherwise. Admins only. (nullable)
Version history: Version history:
* 4.0.0: added * 4.0.0: added
@ -3704,9 +3958,9 @@ class FeaturedTag(AttribAccessDict):
* 3.0.0: added * 3.0.0: added
""" """
last_status_at: "datetime" last_status_at: "Optional[datetime]"
""" """
The last time a public status containing this hashtag was added to this instance's database (can be None if there are none). The last time a public status containing this hashtag was added to this instance's database (can be None if there are none). (nullable)
Version history: Version history:
* 3.0.0: added * 3.0.0: added
@ -4135,7 +4389,7 @@ class AdminAccount(AttribAccessDict):
* 2.9.1: added * 2.9.1: added
""" """
invited_by_account_id : "Optional[IdType]" invited_by_account_id: "Optional[IdType]"
""" """
Present if the user was created via invite and set to the inviting users id. (optional) Present if the user was created via invite and set to the inviting users id. (optional)
@ -4202,9 +4456,9 @@ class AdminMeasure(AttribAccessDict):
* 3.5.0: added * 3.5.0: added
""" """
human_value: "str" human_value: "Optional[str]"
""" """
Human readable variant of the measure returned. Human readable variant of the measure returned. (nullable)
Version history: Version history:
* 3.5.0: added * 3.5.0: added
@ -4457,7 +4711,15 @@ class AdminDomainBlock(AttribAccessDict):
* 4.0.0: added * 4.0.0: added
""" """
_version = "4.0.0" digest: "Optional[str]"
"""
SHA256 hex digest of the blocked domain. (nullable)
Version history:
* 4.3.0: added
"""
_version = "4.3.0"
class AdminCanonicalEmailBlock(AttribAccessDict): class AdminCanonicalEmailBlock(AttribAccessDict):
""" """
@ -4929,7 +5191,7 @@ class AccountCreationError(AttribAccessDict):
* 2.7.0: added * 2.7.0: added
""" """
details: "AccountCreationErrorDetails" details: "AccountCreationErrorDetails[null]"
""" """
A dictionary giving more details about what fields caused errors and in which ways. A dictionary giving more details about what fields caused errors and in which ways.
@ -4946,7 +5208,7 @@ class AccountCreationErrorDetails(AttribAccessDict):
See also (Mastodon API documentation): https://docs.joinmastodon.org/methods/accounts/#create See also (Mastodon API documentation): https://docs.joinmastodon.org/methods/accounts/#create
""" """
username: "Optional[AccountCreationErrorDetailsField]" username: "Optional[EntityList[AccountCreationErrorDetailsField]]"
""" """
An object giving more details about an error caused by the username. (optional) An object giving more details about an error caused by the username. (optional)
@ -4954,7 +5216,7 @@ class AccountCreationErrorDetails(AttribAccessDict):
* 3.4.0: added * 3.4.0: added
""" """
password: "Optional[AccountCreationErrorDetailsField]" password: "Optional[EntityList[AccountCreationErrorDetailsField]]"
""" """
An object giving more details about an error caused by the password. (optional) An object giving more details about an error caused by the password. (optional)
@ -4962,7 +5224,7 @@ class AccountCreationErrorDetails(AttribAccessDict):
* 3.4.0: added * 3.4.0: added
""" """
email: "Optional[AccountCreationErrorDetailsField]" email: "Optional[EntityList[AccountCreationErrorDetailsField]]"
""" """
An object giving more details about an error caused by the e-mail. (optional) An object giving more details about an error caused by the e-mail. (optional)
@ -4970,7 +5232,7 @@ class AccountCreationErrorDetails(AttribAccessDict):
* 3.4.0: added * 3.4.0: added
""" """
agreement: "Optional[AccountCreationErrorDetailsField]" agreement: "Optional[EntityList[AccountCreationErrorDetailsField]]"
""" """
An object giving more details about an error caused by the usage policy agreement. (optional) An object giving more details about an error caused by the usage policy agreement. (optional)
@ -4978,7 +5240,7 @@ class AccountCreationErrorDetails(AttribAccessDict):
* 3.4.0: added * 3.4.0: added
""" """
locale: "Optional[AccountCreationErrorDetailsField]" locale: "Optional[EntityList[AccountCreationErrorDetailsField]]"
""" """
An object giving more details about an error caused by the locale. (optional) An object giving more details about an error caused by the locale. (optional)
@ -4986,7 +5248,7 @@ class AccountCreationErrorDetails(AttribAccessDict):
* 3.4.0: added * 3.4.0: added
""" """
reason: "Optional[AccountCreationErrorDetailsField]" reason: "Optional[EntityList[AccountCreationErrorDetailsField]]"
""" """
An object giving more details about an error caused by the registration reason. (optional) An object giving more details about an error caused by the registration reason. (optional)
@ -5020,3 +5282,5 @@ class AccountCreationErrorDetailsField(AttribAccessDict):
""" """
_version = "3.4.0" _version = "3.4.0"

Wyświetl plik

@ -4,8 +4,6 @@ from datetime import datetime, timezone
import dateutil import dateutil
import dateutil.parser import dateutil.parser
from collections import OrderedDict from collections import OrderedDict
import inspect
import json
from mastodon.compat import PurePath from mastodon.compat import PurePath
import sys import sys
@ -192,7 +190,7 @@ def real_issubclass(type1, type2orig):
return issubclass(type1, tuple(valid_types)) return issubclass(type1, tuple(valid_types))
# Helper functions for typecasting attempts # Helper functions for typecasting attempts
def try_cast(t, value, retry = True): def try_cast(t, value, retry = True, union_specializer = None):
""" """
Base case casting function. Handles: Base case casting function. Handles:
* Casting to any AttribAccessDict subclass (directly, no special handling) * Casting to any AttribAccessDict subclass (directly, no special handling)
@ -207,11 +205,13 @@ def try_cast(t, value, retry = True):
t = resolve_type(t) t = resolve_type(t)
if type(t) == TypeVar: # TypeVar early out with an attempt at coercing dicts if type(t) == TypeVar: # TypeVar early out with an attempt at coercing dicts
if isinstance(value, dict): if isinstance(value, dict):
return try_cast(AttribAccessDict, value, False) return try_cast(AttribAccessDict, value, False, union_specializer)
else: else:
return value return value
try: try:
if real_issubclass(t, AttribAccessDict): if real_issubclass(t, AttribAccessDict):
if union_specializer is not None:
value["__union_specializer"] = union_specializer
value = t(**value) value = t(**value)
elif real_issubclass(t, bool): elif real_issubclass(t, bool):
if isinstance(value, str): if isinstance(value, str):
@ -251,6 +251,9 @@ def try_cast(t, value, retry = True):
# One last time # One last time
value = None value = None
elif real_issubclass(t, list): elif real_issubclass(t, list):
if not t in [PaginatableList, NonPaginatableList]:
# we never want base case lists
t = NonPaginatableList
value = t(value) value = t(value)
else: else:
if real_issubclass(value.__class__, dict): if real_issubclass(value.__class__, dict):
@ -259,13 +262,14 @@ def try_cast(t, value, retry = True):
value = t(value) value = t(value)
except Exception as e: except Exception as e:
if retry and isinstance(value, dict): if retry and isinstance(value, dict):
value = try_cast(AttribAccessDict, value, False) value = try_cast(AttribAccessDict, value, False, union_specializer)
return value return value
def try_cast_recurse(t, value): def try_cast_recurse(t, value, union_specializer=None):
""" """
Non-dict compound type casting function. Handles: Non-dict compound type casting function. Handles:
* Casting to list, tuple, EntityList or (Non)PaginatableList, converting all elements to the correct type recursively * Casting to list, tuple, EntityList or (Non)PaginatableList, converting all elements to the correct type recursively
+ Casting to Union, use union_specializer to special case the union type to the correct one
* Casting to Union, trying all types in the union until one works * Casting to Union, trying all types in the union until one works
Gives up and returns as-is if none of the above work. Gives up and returns as-is if none of the above work.
""" """
@ -276,24 +280,45 @@ def try_cast_recurse(t, value):
if hasattr(t, '__origin__') or hasattr(t, '__extra__'): if hasattr(t, '__origin__') or hasattr(t, '__extra__'):
orig_type = get_type_class(t) orig_type = get_type_class(t)
if orig_type in (list, tuple, EntityList, NonPaginatableList, PaginatableList): if orig_type in (list, tuple, EntityList, NonPaginatableList, PaginatableList):
if orig_type == list:
orig_type = NonPaginatableList
value_cast = [] value_cast = []
type_args = t.__args__ type_args = t.__args__
if len(type_args) == 1: if len(type_args) == 1:
type_args = type_args * len(value) type_args = type_args * len(value)
for element_type, v in zip(type_args, value): for element_type, v in zip(type_args, value):
value_cast.append(try_cast_recurse(element_type, v)) value_cast.append(try_cast_recurse(element_type, v, union_specializer))
value = orig_type(value_cast) value = orig_type(value_cast)
elif orig_type is Union: elif orig_type is Union:
for sub_t in t.__args__: real_type = None
value = try_cast_recurse(sub_t, value) if union_specializer is not None:
testing_t = sub_t from mastodon.types import MediaAttachmentImageMetadata, MediaAttachmentVideoMetadata, MediaAttachmentAudioMetadata
real_type = {
"image": MediaAttachmentImageMetadata,
"video": MediaAttachmentVideoMetadata,
"audio": MediaAttachmentAudioMetadata,
"gifv": MediaAttachmentVideoMetadata,
}.get(union_specializer, None)
if real_type in t.__args__:
value = try_cast_recurse(real_type, value, union_specializer)
testing_t = real_type
if hasattr(t, '__origin__') or hasattr(t, '__extra__'): if hasattr(t, '__origin__') or hasattr(t, '__extra__'):
testing_t = get_type_class(sub_t) testing_t = get_type_class(real_type)
if isinstance(value, testing_t): else:
break for sub_t in t.__args__:
value = try_cast_recurse(sub_t, value, union_specializer)
testing_t = sub_t
if hasattr(t, '__origin__') or hasattr(t, '__extra__'):
testing_t = get_type_class(sub_t)
if isinstance(value, testing_t):
break
else:
# uhhh I don't know how we got here but try to cast to the type anyways
value = try_cast(t, value, True, union_specializer)
else:
value = try_cast(t, value, True, union_specializer)
except Exception as e: except Exception as e:
pass pass
value = try_cast(t, value)
return value return value
""" """
@ -360,6 +385,9 @@ class AttribAccessDict(OrderedStrDict):
Constructor that calls through to dict constructor and then sets attributes for all keys. Constructor that calls through to dict constructor and then sets attributes for all keys.
""" """
super(AttribAccessDict, self).__init__() super(AttribAccessDict, self).__init__()
if "__union_specializer" in kwargs:
self.__union_specializer = kwargs["__union_specializer"]
del kwargs["__union_specializer"]
if "__annotations__" in self.__class__.__dict__: if "__annotations__" in self.__class__.__dict__:
for attr, _ in self.__class__.__annotations__.items(): for attr, _ in self.__class__.__annotations__.items():
attr_name = attr attr_name = attr
@ -380,6 +408,8 @@ class AttribAccessDict(OrderedStrDict):
""" """
Override to force access of normal attributes to go through __getattr__ Override to force access of normal attributes to go through __getattr__
""" """
if attr == "_AttribAccessDict__union_specializer":
return super(AttribAccessDict, self).__getattribute__(attr)
if attr == '__class__': if attr == '__class__':
return super(AttribAccessDict, self).__getattribute__(attr) return super(AttribAccessDict, self).__getattribute__(attr)
if attr in self.__class__.__annotations__: if attr in self.__class__.__annotations__:
@ -389,7 +419,7 @@ class AttribAccessDict(OrderedStrDict):
def __getattr__(self, attr): def __getattr__(self, attr):
""" """
Basic attribute getter that throws if attribute is not in dict and supports redirecting access. Basic attribute getter that throws if attribute is not in dict and supports redirecting access.
""" """
if not hasattr(self.__class__, "_access_map"): if not hasattr(self.__class__, "_access_map"):
# Base case: no redirecting # Base case: no redirecting
if attr in self: if attr in self:
@ -415,7 +445,7 @@ class AttribAccessDict(OrderedStrDict):
""" """
Attribute setter that calls through to dict setter but will throw if attribute is not in dict Attribute setter that calls through to dict setter but will throw if attribute is not in dict
""" """
if attr in self: if attr in self or attr == "_AttribAccessDict__union_specializer":
self[attr] = val self[attr] = val
else: else:
raise AttributeError(f"Attribute not found: {attr}") raise AttributeError(f"Attribute not found: {attr}")
@ -425,27 +455,44 @@ class AttribAccessDict(OrderedStrDict):
Dict setter that also sets attributes and tries to typecast if we have an Dict setter that also sets attributes and tries to typecast if we have an
AttribAccessDict or MaybeSnowflakeIdType type hint. AttribAccessDict or MaybeSnowflakeIdType type hint.
For Unions, it will try the types in order. For Unions, we special case explicitly to specialize
""" """
# Collate type hints that we may have # Collate type hints that we may have
type_hints = get_type_hints(self.__class__) type_hints = get_type_hints(self.__class__)
init_hints = get_type_hints(self.__class__.__init__) init_hints = get_type_hints(self.__class__.__init__)
type_hints.update(init_hints) type_hints.update(init_hints)
# Ugly hack: We have to specialize unions by hand because you can't just guess by content generally
# Note for developers: This means type MUST be set before meta. fortunately, we can enforce this via
# the type hints (assuming that the order of annotations is not changed, which python does not guarantee,
# if it ever does: we'll have to add another hack to the constructor)
from mastodon.types import MediaAttachment
if type(self) == MediaAttachment and key == "type":
self.__union_specializer = val
# Do we have a union specializer attribute?
union_specializer = None
if hasattr(self, "_AttribAccessDict__union_specializer"):
union_specializer = self.__union_specializer
# Do typecasting, possibly iterating over a list or tuple # Do typecasting, possibly iterating over a list or tuple
if key in type_hints: if key in type_hints:
type_hint = type_hints[key] type_hint = type_hints[key]
val = try_cast_recurse(type_hint, val) val = try_cast_recurse(type_hint, val, union_specializer)
else: else:
if isinstance(val, dict): if isinstance(val, dict):
val = try_cast_recurse(AttribAccessDict, val) val = try_cast_recurse(AttribAccessDict, val, union_specializer)
elif isinstance(val, list): elif isinstance(val, list):
val = try_cast_recurse(EntityList, val) val = try_cast_recurse(EntityList, val, union_specializer)
# Finally, call out to setattr and setitem proper # Finally, call out to setattr and setitem proper
super(AttribAccessDict, self).__setattr__(key, val) super(AttribAccessDict, self).__setattr__(key, val)
super(AttribAccessDict, self).__setitem__(key, val) super(AttribAccessDict, self).__setitem__(key, val)
# Remove union specializer if we have one
if "_AttribAccessDict__union_specializer" in self:
del self["_AttribAccessDict__union_specializer"]
def __eq__(self, other): def __eq__(self, other):
""" """
Equality checker with casting Equality checker with casting
@ -473,4 +520,4 @@ WebpushCryptoParamsPubkey = Dict[str, str]
WebpushCryptoParamsPrivkey = Dict[str, str] WebpushCryptoParamsPrivkey = Dict[str, str]
"""Backwards compatibility alias""" """Backwards compatibility alias"""
AttribAccessList = PaginatableList AttribAccessList = PaginatableList

Wyświetl plik

@ -0,0 +1,334 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Imports"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Super special from this directory for sure and guaranteed import\n",
"import importlib.util\n",
"import sys\n",
"\n",
"spec = importlib.util.spec_from_file_location(\"mastodon\", \"../mastodon/__init__.py\")\n",
"\n",
"mastodon = importlib.util.module_from_spec(spec)\n",
"sys.modules[\"mastodon\"] = mastodon\n",
"spec.loader.exec_module(mastodon)\n",
"Mastodon = mastodon.Mastodon\n",
"print(mastodon.__file__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Regular normal person imports\n",
"import json\n",
"from datetime import datetime, timedelta, timezone\n",
"import copy\n",
"from typing import List, Union\n",
"import pickle as pkl\n",
"\n",
"# Mastodon.py imports\n",
"from mastodon.types import *\n",
"from mastodon.types_base import real_issubclass"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mastodon_soc = Mastodon(access_token=\"mastosoc_credentials.secret\", debug_requests=True)\n",
"mastodon_ico_admin = Mastodon(access_token = \"../../pytooter_usercred_ADMIN_DANGER.secret\", debug_requests=True)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Manual test zone"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Here you can test things manually during development\n",
"# results = {}\n",
"import pickle as pkl\n",
"#results = pkl.load(open(\"temp_entities.pkl\", 'rb'))\n",
"#mastodon_soc.status(110447003454258227)\n",
"#mastodon_soc.status(110447012773105565).media_attachments[0].meta.original"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entity verification"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"entities = json.load(open(\"return_types_all_current_fixed_bu.json\", \"r\"))\n",
"update_only = \"PreviewCardAuthor\"\n",
"update_only = None\n",
"\n",
"if update_only is None:\n",
" results = {}\n",
"for entity in entities:\n",
" name = entity[\"python_name\"]\n",
" if update_only is None and name in results:\n",
" continue\n",
" if not update_only is None and name != update_only:\n",
" continue\n",
" if entity.get(\"manual_update\") == True:\n",
" continue\n",
" func_call = entity.get(\"func_call_real\")\n",
" if func_call is None:\n",
" func_call = entity[\"func_call\"]\n",
" if func_call == \"TODO_TO_BE_IMPLEMENTED\":\n",
" continue\n",
" mastodon = mastodon_soc\n",
" if entity.get(\"func_alternate_acc\") == True:\n",
" mastodon = mastodon_ico_admin\n",
" print(\"Checking\", name)\n",
" print(\" *\", func_call)\n",
" results[name] = [eval(func_call)]\n",
" func_call = entity.get(\"func_call_additional\")\n",
" if not func_call is None:\n",
" print(\" *\", func_call)\n",
" results[name].append(eval(func_call))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"entities = json.load(open(\"return_types_all_current_fixed_bu.json\", \"r\"))\n",
"\n",
"entities_by_name = {}\n",
"for entity in entities:\n",
" entities_by_name[entity[\"python_name\"]] = entity\n",
"\n",
"for result_name in results:\n",
" entity = entities_by_name[result_name]\n",
" entity_fields = entity[\"fields\"]\n",
" field_types_ok = {}\n",
" field_types_found = {}\n",
" for result in results[result_name]:\n",
" for field in result:\n",
" if not field in field_types_ok:\n",
" field_types_ok[field] = True\n",
" field_types_found[field] = []\n",
" entity_field = entity_fields.get(field)\n",
" if entity_field is None:\n",
" entity_field = entity_fields.get(field.replace(\"_\", \":\")) # hack for fields with colons. the actual json has this documented, but we don't care here\n",
" if entity_field is None:\n",
" print(result_name + \":\", field, \"not documented\")\n",
" continue\n",
" if result[field] is None and not (entity_field[\"is_nullable\"] or entity_field[\"is_optional\"]):\n",
" print(result_name + \":\", field, \"documented as not nullable/optional but is None\") \n",
" else:\n",
" field_types_found[field].append(type(result[field]))\n",
" try:\n",
" if not real_issubclass(type(result[field]), eval(entity_field[\"field_type\"])):\n",
" if not (entity_field[\"is_nullable\"] or entity_field[\"is_optional\"]) and result[field] is None:\n",
" field_types_ok[field] = False\n",
" except Exception as e:\n",
" field_types_ok[field] = False\n",
" for field in field_types_ok:\n",
" if not field_types_ok[field]:\n",
" if not set(field_types_found[field]) == set([type(None)]):\n",
" entity_fields_real = set(field_types_found[field]) - set([type(None)])\n",
" if not (entity_fields[field][\"field_type\"] == \"EntityList\" and len(entity_fields_real) == 1 and list(entity_fields_real)[0] == NonPaginatableList):\n",
" print(result_name + \":\", field, \"documented as\", entity_fields[field][\"field_type\"], \"but does not parse as such in all cases (found types:\", field_types_found[field], \")\")\n",
" if set(field_types_found[field]) == set(str(type(None))):\n",
" print(result_name + \":\", field, \"documented as\", entity_fields[field][\"field_type\"], \"but only found as None\")\n",
"for entity_name in entities_by_name:\n",
" entity = entities_by_name[entity_name]\n",
" entity_fields = entity[\"fields\"]\n",
" if not entity_name in results:\n",
" print(\"entity\", entity_name + \":\", \"documented but never retrieved\")\n",
" continue\n",
" for field in entity_fields:\n",
" found = False\n",
" for result in results[entity_name]:\n",
" if field in result:\n",
" found = True\n",
" else:\n",
" if not entity_fields[field][\"is_optional\"] and not entity_fields[field].get(\"api_version\") is None:\n",
" print(entity_name + \": field\", field, \"documented as not optional but missing from some retrieved entities\")\n",
" if not found:\n",
" print(entity_name + \": field\", field, \"documented but missing from all retrieved entities\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mastodon_soc.featured_tags()[0]"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### JSON normalization"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"entities = json.load(open(\"return_types_all_current_fixed_bu.json\", \"r\"))\n",
"for entity in entities:\n",
" print(entity)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python generation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from mastodon.utility import max_version\n",
"\n",
"def add_dot(str):\n",
" if str[-1] == \".\":\n",
" return str\n",
" return str + \".\"\n",
"\n",
"entities = json.load(open(\"return_types_all_current_fixed_bu.json\", \"r\"))\n",
"\n",
"all_entities_text = \"\"\n",
"for entity in entities:\n",
" entity_version = \"0.0.0\"\n",
" all_entities_text += f\"class {entity['python_name']}(AttribAccessDict):\\n\"\n",
" all_entities_text += f\" \\\"\\\"\\\"\\n {add_dot(entity['description'])}\\n\\n\"\n",
" all_entities_text += f\" See also (Mastodon API documentation): {entity['masto_doc_link']}\\n\"\n",
" all_entities_text += f\" \\\"\\\"\\\"\\n\"\n",
" all_entities_text += \"\\n\"\n",
" rename_map = {}\n",
" access_map = {}\n",
" for field in entity[\"fields\"]:\n",
" if \"moved_path\" in entity[\"fields\"][field]:\n",
" access_map[field] = entity[\"fields\"][field][\"moved_path\"]\n",
" field_name = field\n",
" if \"python_name\" in entity[\"fields\"][field]:\n",
" field_name = entity[\"fields\"][field][\"python_name\"]\n",
" rename_map[field] = field_name\n",
" type_str = entity[\"fields\"][field][\"field_type\"]\n",
" if entity[\"fields\"][field][\"field_subtype\"] is not None:\n",
" type_str += f\"[{entity['fields'][field]['field_subtype']}]\"\n",
" if entity[\"fields\"][field][\"is_optional\"] or entity[\"fields\"][field][\"is_nullable\"]:\n",
" type_str = f\"Optional[{type_str}]\"\n",
" type_str = f\"\\\"{type_str}\\\"\" \n",
" all_entities_text += f\" {field_name}: {type_str}\\n\"\n",
" all_entities_text += f\" \\\"\\\"\\\"\\n\"\n",
" if \"is_deprecated\" in entity[\"fields\"][field] and entity[\"fields\"][field][\"is_deprecated\"] == True:\n",
" all_entities_text += f\" THIS FIELD IS DEPRECATED. IT IS RECOMMENDED THAT YOU DO NOT USE IT.\\n\\n\"\n",
" all_entities_text += f\" {add_dot(entity['fields'][field]['description'])}\"\n",
" if entity[\"fields\"][field][\"is_optional\"]:\n",
" if entity[\"fields\"][field][\"is_nullable\"]:\n",
" all_entities_text += \" (optional, nullable)\"\n",
" else:\n",
" all_entities_text += \" (optional)\"\n",
" elif entity[\"fields\"][field][\"is_nullable\"]:\n",
" all_entities_text += \" (nullable)\"\n",
" all_entities_text += \"\\n\"\n",
" if entity[\"fields\"][field].get(\"field_structuretype\", None) is not None:\n",
" all_entities_text += f\" Should contain (as text): {entity['fields'][field]['field_structuretype']}\\n\"\n",
" all_entities_text += \"\\n Version history:\\n\"\n",
" for version, changed in entity[\"fields\"][field][\"version_history\"]:\n",
" entity_version = max_version(entity_version, version)\n",
" all_entities_text += f\" * {version}: {changed}\\n\"\n",
" all_entities_text += \" \\\"\\\"\\\"\\n\\n\"\n",
" all_entities_text += f\" _version = \\\"{entity_version}\\\"\\n\"\n",
" if len(rename_map) > 0:\n",
" all_entities_text += \" _rename_map = {\\n\"\n",
" for field in rename_map:\n",
" all_entities_text += f\" \\\"{rename_map[field]}\\\": \\\"{field}\\\",\\n\"\n",
" all_entities_text += \" }\\n\"\n",
" if len(access_map) > 0:\n",
" all_entities_text += \" _access_map = {\\n\"\n",
" for field in access_map:\n",
" all_entities_text += f\" \\\"{field}\\\": \\\"{access_map[field]}\\\",\\n\"\n",
" all_entities_text += \" }\\n\"\n",
" all_entities_text += \"\\n\"\n",
"print(\"\"\"from __future__ import annotations # python< 3.9 compat\n",
"from datetime import datetime\n",
"from typing import Union, Optional, Tuple, List, IO, Dict\n",
"from mastodon.types_base import AttribAccessDict, IdType, MaybeSnowflakeIdType, PaginationInfo, PrimitiveIdType, EntityList, PaginatableList, NonPaginatableList, PathOrFile, WebpushCryptoParamsPubkey, WebpushCryptoParamsPrivkey, try_cast_recurse, try_cast, real_issubclass\n",
"\"\"\") \n",
"print(all_entities_text)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "mastopy_39",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

Wyświetl plik

@ -201,6 +201,21 @@
], ],
"enum": null "enum": null
}, },
"uri": {
"description": "Webfinger-resolvable URI for this account",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"field_structuretype": "URL",
"version_history": [
[
"4.2.0",
"added"
]
],
"enum": null
},
"avatar": { "avatar": {
"description": "URL for this users avatar, can be animated", "description": "URL for this users avatar, can be animated",
"field_type": "str", "field_type": "str",
@ -381,8 +396,8 @@
"is_deprecated": true, "is_deprecated": true,
"field_type": "EntityList", "field_type": "EntityList",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": true,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"0.1.0", "0.1.0",
@ -433,6 +448,34 @@
] ]
], ],
"enum": null "enum": null
},
"indexable": {
"description": "Boolean indicating whether public posts by this account should be searchable by anyone.",
"field_type": "bool",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.2.0",
"added"
]
],
"enum": null
},
"hide_collections": {
"description": "Boolean indicating whether a user has chosen to hide their network (followers/followed accounts).",
"field_type": "bool",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.1.0",
"added"
]
],
"enum": null
} }
} }
}, },
@ -638,7 +681,7 @@
"field_subtype": null, "field_subtype": null,
"field_structuretype": "TwoLetterLanguageCodeEnum", "field_structuretype": "TwoLetterLanguageCodeEnum",
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.4.2", "2.4.2",
@ -674,6 +717,48 @@
] ]
], ],
"enum": null "enum": null
},
"indexable": {
"description": "Boolean indicating whether public posts by this user should be searchable by anyone.",
"field_type": "bool",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.2.0",
"added"
]
],
"enum": null
},
"hide_collections": {
"description": "Boolean indicating whether the user has chosen to hide their network (followers/followed accounts).",
"field_type": "bool",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.1.0",
"added"
]
],
"enum": null
},
"discoverable": {
"description": "Indicates whether or not the user is visible on the discovery page",
"field_type": "bool",
"field_subtype": null,
"is_optional": false,
"is_nullable": true,
"version_history": [
[
"3.1.0",
"added"
]
],
"enum": null
} }
} }
}, },
@ -915,9 +1000,9 @@
} }
}, },
"mentions": { "mentions": {
"description": "A list Mentions this status includes", "description": "A list of StatusMention this status includes",
"field_type": "EntityList", "field_type": "EntityList",
"field_subtype": "Account", "field_subtype": "StatusMention",
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": false,
"version_history": [ "version_history": [
@ -1212,7 +1297,7 @@
"description": "The current state of the poll options at this revision. Note that edits changing the poll options will be collapsed together into one edit, since this action resets the poll.", "description": "The current state of the poll options at this revision. Note that edits changing the poll options will be collapsed together into one edit, since this action resets the poll.",
"field_type": "Poll", "field_type": "Poll",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": true,
"is_nullable": false, "is_nullable": false,
"version_history": [ "version_history": [
[ [
@ -1489,7 +1574,7 @@
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.7.0", "2.7.0",
@ -2077,7 +2162,7 @@
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"3.0.0", "3.0.0",
@ -2099,6 +2184,20 @@
"manual_update": false, "manual_update": false,
"description": "Information about an app (in terms of the API)", "description": "Information about an app (in terms of the API)",
"fields": { "fields": {
"id": {
"description": "ID of the application",
"field_type": "IdType",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"2.7.0",
"added"
]
],
"enum": null
},
"name": { "name": {
"description": "The applications name", "description": "The applications name",
"field_type": "str", "field_type": "str",
@ -2137,10 +2236,64 @@
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": false,
"is_deprecated": true,
"version_history": [ "version_history": [
[ [
"2.8.0", "2.8.0",
"added" "added"
],
[
"4.3.0",
"deprecated"
]
],
"enum": null
},
"redirect_uri": {
"description": "The applications redirect URI or urn:ietf:wg:oauth:2.0:oob. Deprecated, it is recommended to use redirect_uris instead.",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"is_deprecated": true,
"version_history": [
[
"0.0.0",
"added"
],
[
"4.3.0",
"deprecated"
]
],
"enum": null
},
"redirect_uris": {
"description": "The applications redirect URI or urn:ietf:wg:oauth:2.0:oob. Deprecated, it is recommended to use redirect_uris instead.",
"field_type": "EntityList",
"field_subtype": "str",
"is_optional": false,
"is_nullable": false,
"field_structuretype": "URL",
"version_history": [
[
"4.3.0",
"added"
]
],
"enum": null
},
"scopes": {
"description": "The applications available scopes.",
"field_type": "EntityList",
"field_subtype": "str",
"is_optional": false,
"is_nullable": false,
"field_structuretype": "Scopes",
"version_history": [
[
"4.3.0",
"added"
] ]
], ],
"enum": null "enum": null
@ -2708,12 +2861,30 @@
"description": "In case of \"mention\", the mentioning status In case of reblog / favourite, the reblogged / favourited status", "description": "In case of \"mention\", the mentioning status In case of reblog / favourite, the reblogged / favourited status",
"field_type": "Status", "field_type": "Status",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": true,
"is_nullable": false, "is_nullable": false,
"version_history": [ "version_history": [
[ [
"0.9.9", "0.9.9",
"added" "added"
],
[
"4.0.0",
"is now optional"
]
],
"enum": null
},
"group_key": {
"description": "A key to group notifications by. Structure is unspecified and subject to change, so please do not make assumptions about it.",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
] ]
], ],
"enum": null "enum": null
@ -2814,6 +2985,20 @@
] ]
], ],
"enum": null "enum": null
},
"exclusive": {
"description": "Boolean indicating whether users on this list are removed from the home feed (appearing exclusively as part of the list). nb: This setting applies to posts at the time they are put into a feed.",
"field_type": "bool",
"field_subtype": null,
"is_optional": true,
"is_nullable": false,
"version_history": [
[
"4.2.0",
"added"
]
],
"enum": null
} }
} }
}, },
@ -2901,7 +3086,7 @@
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"field_structuretype": "URL", "field_structuretype": "URL",
"version_history": [ "version_history": [
[ [
@ -2917,7 +3102,7 @@
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"field_structuretype": "URL", "field_structuretype": "URL",
"is_optional": false, "is_optional": true,
"is_nullable": false, "is_nullable": false,
"version_history": [ "version_history": [
[ [
@ -3006,7 +3191,7 @@
"masto_doc_link": "https://docs.joinmastodon.org/entities/MediaAttachment/", "masto_doc_link": "https://docs.joinmastodon.org/entities/MediaAttachment/",
"func_alternate_acc": false, "func_alternate_acc": false,
"manual_update": false, "manual_update": false,
"description": "An object holding metadata about a media attachment and its thumbnail.", "description": "An object holding metadata about a media attachment and its thumbnail. In addition to the documented fields, there may be additional fields. These are not documented, not guaranteed to be present (they are a Mastodon implementation detail), and may change without notice, so relying on them is not recommended.",
"fields": { "fields": {
"original": { "original": {
"description": "Metadata for the original media attachment", "description": "Metadata for the original media attachment",
@ -3038,7 +3223,7 @@
"description": "Information about accent colors for the media.", "description": "Information about accent colors for the media.",
"field_type": "MediaAttachmentColors", "field_type": "MediaAttachmentColors",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": true,
"is_nullable": false, "is_nullable": false,
"version_history": [ "version_history": [
[ [
@ -3051,7 +3236,7 @@
"description": "Information about the focus point for the media.", "description": "Information about the focus point for the media.",
"field_type": "MediaAttachmentFocusPoint", "field_type": "MediaAttachmentFocusPoint",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": true,
"is_nullable": false, "is_nullable": false,
"version_history": [ "version_history": [
[ [
@ -3132,11 +3317,11 @@
"python_name": "MediaAttachmentVideoMetadata", "python_name": "MediaAttachmentVideoMetadata",
"func_call": "mastodon.media_post(\"video.mp4\").meta.original", "func_call": "mastodon.media_post(\"video.mp4\").meta.original",
"func_call_real": "mastodon.status(110447001287656894).media_attachments[0].meta.original", "func_call_real": "mastodon.status(110447001287656894).media_attachments[0].meta.original",
"func_call_additional": "mastodon.status(110447018236380496).media_attachments[0].meta.original", "func_call_additional": "mastodon.status(113358687695262945).media_attachments[0].meta.original",
"masto_doc_link": "https://docs.joinmastodon.org/entities/MediaAttachment/", "masto_doc_link": "https://docs.joinmastodon.org/entities/MediaAttachment/",
"func_alternate_acc": false, "func_alternate_acc": false,
"manual_update": false, "manual_update": false,
"description": "Metadata for a video or gifv media attachment.", "description": "Metadata for a video attachment. This can be a proper video, or a gifv (a looping, soundless animation). Both use the same data model currently, though there is a possibility that they could be split in the future.",
"fields": { "fields": {
"width": { "width": {
"description": "Width of the video in pixels", "description": "Width of the video in pixels",
@ -3424,21 +3609,26 @@
"enum": null "enum": null
}, },
"author_name": { "author_name": {
"description": "Name of the embedded contents author", "description": "Name of the embedded contents author. Deprecated in favour of the `authors` field.",
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": false,
"is_deprecated": true,
"version_history": [ "version_history": [
[ [
"1.3.0", "1.3.0",
"added" "added"
],
[
"4.3.0",
"deprecated"
] ]
], ],
"enum": null "enum": null
}, },
"author_url": { "author_url": {
"description": "URL pointing to the embedded contents author", "description": "URL pointing to the embedded contents author. Deprecated in favour of the `authors` field.",
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
@ -3448,6 +3638,10 @@
[ [
"1.3.0", "1.3.0",
"added" "added"
],
[
"4.3.0",
"deprecated"
] ]
], ],
"enum": null "enum": null
@ -3567,6 +3761,105 @@
] ]
], ],
"enum": null "enum": null
},
"authors": {
"description": "List of fediverse accounts of the authors of this post, as `PreviewCardAuthor`.",
"field_type": "EntityList",
"field_subtype": "PreviewCardAuthor",
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
]
],
"enum": null
},
"image_description": {
"description": "Alt text / image description for the image preview for the card.",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.2.0",
"added"
]
],
"enum": null
},
"published_at": {
"description": "Publication time of the embedded content, if available, as a `datetime` object.",
"field_type": "datetime",
"field_subtype": null,
"is_optional": false,
"is_nullable": true,
"version_history": [
[
"4.2.0",
"added"
]
],
"enum": null
}
}
},
{
"name": "Preview Card Author",
"func_call": "mastodon.status_card(<status id>).authors[0]",
"func_call_real": "mastodon.status_card(113481707975926080).authors[0]",
"python_name": "PreviewCardAuthor",
"masto_doc_link": "https://docs.joinmastodon.org/entities/PreviewCardAuthor/",
"func_call_additional": null,
"func_alternate_acc": false,
"manual_update": false,
"description": "A preview card attached to a status, e.g. for an embedded video or link.",
"fields": {
"name": {
"description": "Name of the embedded contents author.",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"is_deprecated": true,
"version_history": [
[
"4.3.0",
"added"
]
],
"enum": null
},
"url": {
"description": "URL pointing to the embedded contents author.",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"field_structuretype": "URL",
"version_history": [
[
"4.3.0",
"added"
]
],
"enum": null
},
"account": {
"description": "Account of the author of this post, as `Account`.",
"field_type": "Account",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
]
],
"enum": null
} }
} }
}, },
@ -3742,7 +4035,7 @@
] ]
], ],
"enum": null "enum": null
}, },
"short_description": { "short_description": {
"description": "An very brief text only instance description. Moved to 'description' for the v2 API.", "description": "An very brief text only instance description. Moved to 'description' for the v2 API.",
"moved_path": "description", "moved_path": "description",
@ -3934,7 +4227,7 @@
"added" "added"
] ]
] ]
}, },
"rules": { "rules": {
"description": "List of Rules with `id` and `text` fields, one for each server rule set by the admin", "description": "List of Rules with `id` and `text` fields, one for each server rule set by the admin",
"field_type": "EntityList", "field_type": "EntityList",
@ -4119,7 +4412,7 @@
"added" "added"
] ]
] ]
}, },
"description": { "description": {
"description": "A brief instance description set by the admin. Contains what in the v1 version was the short description.", "description": "A brief instance description set by the admin. Contains what in the v1 version was the short description.",
"field_type": "str", "field_type": "str",
@ -4176,13 +4469,13 @@
}, },
"configuration": { "configuration": {
"description": "Various instance configuration settings - especially various limits (character counts, media upload sizes, ...)", "description": "Various instance configuration settings - especially various limits (character counts, media upload sizes, ...)",
"field_type": "InstanceConfiguration", "field_type": "InstanceConfigurationV2",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": false,
"version_history": [ "version_history": [
[ [
"3.1.4", "4.0.0",
"added" "added"
] ]
] ]
@ -4226,6 +4519,73 @@
"added" "added"
] ]
] ]
},
"icon": {
"description": "The instance icon, as a list of `InstanceIcon`s, with entries representing different available size variants.",
"field_type": "EntityList",
"field_subtype": "InstanceIcon",
"is_optional": false,
"is_nullable": false,
"field_structuretype": "URL",
"version_history": [
[
"4.3.0",
"added"
]
]
},
"api_versions": {
"description": "A list of API versions supported by this instance, each as an entry in a dict with the name of the implementation as the key (such as 'mastodon'). The exact format is unspecified, any fork or implementation can put what if feels like there. Mastodon currently puts just '2'",
"field_type": "AttribAccessDict",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
]
]
}
}
},
{
"name": "Instance icon",
"python_name": "InstanceIcon",
"func_call": "mastodon.instance_v2().icon[0]",
"masto_doc_link": "https://docs.joinmastodon.org/methods/instance/#InstanceIcon",
"func_call_real": null,
"func_call_additional": null,
"func_alternate_acc": false,
"manual_update": false,
"description": "Icon for the instance, in a specific size.",
"fields": {
"src": {
"description": "URL for this icon size",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"field_structuretype": "URL",
"version_history": [
[
"4.3.0",
"added"
]
]
},
"size": {
"description": "Textual representation of the icon size in pixels as (width)x(height) string, e.g. '64x64'",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
]
]
} }
} }
}, },
@ -4323,6 +4683,46 @@
"added" "added"
] ]
] ]
},
"vapid": {
"description": "VAPID key used by this instance to sign webpush requests. Only present for the v2 API variant of the instance API.",
"field_type": "InstanceVapidKey",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"api_version": "v2",
"version_history": [
[
"4.3.0",
"added"
]
]
}
}
},
{
"name": "Instance vapid key",
"python_name": "InstanceVapidKey",
"func_call": "mastodon.instance_v2().configuration.vapid",
"masto_doc_link": "https://docs.joinmastodon.org/methods/instance/",
"func_call_real": null,
"func_call_additional": null,
"func_alternate_acc": false,
"manual_update": false,
"description": "The VAPID key used by this instance to sign webpush requests.",
"fields": {
"public_key": {
"description": "The public key in VAPID format.",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
]
]
} }
} }
}, },
@ -4330,7 +4730,7 @@
"name": "Instance urls (v2)", "name": "Instance urls (v2)",
"python_name": "InstanceURLsV2", "python_name": "InstanceURLsV2",
"func_call": "mastodon.instance_v2().configuration.urls", "func_call": "mastodon.instance_v2().configuration.urls",
"func_call_additional": "mastodon.instance_v1().urls", "func_call_additional": null,
"masto_doc_link": "https://docs.joinmastodon.org/entities/Instance/", "masto_doc_link": "https://docs.joinmastodon.org/entities/Instance/",
"func_call_real": null, "func_call_real": null,
"func_alternate_acc": false, "func_alternate_acc": false,
@ -4604,7 +5004,7 @@
"enum": null "enum": null
}, },
"text": { "text": {
"description": "The rule to be followed.", "description": "The rule to be followed, in few words.",
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
@ -4616,13 +5016,27 @@
] ]
], ],
"enum": null "enum": null
},
"hint": {
"description": "Potentially, the rule to be followed, in more words.",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
]
],
"enum": null
} }
} }
}, },
{ {
"name": "Instance registration information", "name": "Instance registration information",
"python_name": "InstanceRegistrations", "python_name": "InstanceRegistrations",
"func_call": "mastodon.instance().registrations", "func_call": "mastodon.instance_v2().registrations",
"masto_doc_link": "https://docs.joinmastodon.org/entities/Instance/", "masto_doc_link": "https://docs.joinmastodon.org/entities/Instance/",
"func_call_real": null, "func_call_real": null,
"func_call_additional": null, "func_call_additional": null,
@ -4750,6 +5164,19 @@
"added" "added"
] ]
] ]
},
"max_pinned_statuses": {
"description": "The maximum number of pinned statuses for an account.",
"field_type": "int",
"field_subtype": null,
"is_optional": false,
"is_nullable": false,
"version_history": [
[
"4.3.0",
"added"
]
]
} }
} }
}, },
@ -4808,7 +5235,7 @@
{ {
"name": "Instance translation configuration", "name": "Instance translation configuration",
"python_name": "InstanceTranslationConfiguration", "python_name": "InstanceTranslationConfiguration",
"func_call": "mastodon.instance().configuration.translation", "func_call": "mastodon.instance_v2().configuration.translation",
"masto_doc_link": "https://docs.joinmastodon.org/methods/instance/", "masto_doc_link": "https://docs.joinmastodon.org/methods/instance/",
"func_call_real": null, "func_call_real": null,
"func_call_additional": null, "func_call_additional": null,
@ -5265,7 +5692,7 @@
"python_name": "NodeinfoMetadata", "python_name": "NodeinfoMetadata",
"masto_doc_link": "https://github.com/jhass/nodeinfo", "masto_doc_link": "https://github.com/jhass/nodeinfo",
"func_call": "mastodon.instance_nodeinfo().metadata", "func_call": "mastodon.instance_nodeinfo().metadata",
"description": "Nodeinfo extra metadata.", "description": "Nodeinfo extra metadata. Entirely freeform, be careful about consuming it programatically. Survey of real world usage: https://codeberg.org/thefederationinfo/nodeinfo_metadata_survey",
"fields": {} "fields": {}
}, },
{ {
@ -5669,11 +6096,11 @@
"enum": null "enum": null
}, },
"forwarded": { "forwarded": {
"description": "Whether a report was forwarded to a remote instance.", "description": "Whether a report was forwarded to a remote instance. Can be None.",
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"4.0.0", "4.0.0",
@ -5823,7 +6250,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.4.0", "2.4.0",
@ -5837,7 +6264,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.4.0", "2.4.0",
@ -5851,7 +6278,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.4.0", "2.4.0",
@ -5865,7 +6292,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.4.0", "2.4.0",
@ -5879,7 +6306,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.8.0", "2.8.0",
@ -5893,7 +6320,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"2.4.0", "2.4.0",
@ -5907,7 +6334,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"3.1.0", "3.1.0",
@ -5921,7 +6348,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"3.3.0", "3.3.0",
@ -5935,7 +6362,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"3.5.0", "3.5.0",
@ -5949,7 +6376,7 @@
"field_type": "bool", "field_type": "bool",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"4.0.0", "4.0.0",
@ -6248,7 +6675,7 @@
"field_type": "datetime", "field_type": "datetime",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"3.0.0", "3.0.0",
@ -6613,7 +7040,7 @@
{ {
"name": "Announcement reaction (streaming edition)", "name": "Announcement reaction (streaming edition)",
"python_name": "StreamReaction", "python_name": "StreamReaction",
"func_call": "mastodon.announcements()[0].reactions[0]", "func_call": "TODO_TO_BE_IMPLEMENTED",
"func_alternate_acc": true, "func_alternate_acc": true,
"masto_doc_link": "https://docs.joinmastodon.org/methods/streaming/", "masto_doc_link": "https://docs.joinmastodon.org/methods/streaming/",
"func_call_real": null, "func_call_real": null,
@ -6983,7 +7410,7 @@
], ],
"enum": null "enum": null
}, },
"invited_by_account_id ": { "invited_by_account_id": {
"description": "Present if the user was created via invite and set to the inviting users id.", "description": "Present if the user was created via invite and set to the inviting users id.",
"field_type": "IdType", "field_type": "IdType",
"field_subtype": null, "field_subtype": null,
@ -7114,7 +7541,7 @@
"field_type": "str", "field_type": "str",
"field_subtype": null, "field_subtype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false, "is_nullable": true,
"version_history": [ "version_history": [
[ [
"3.5.0", "3.5.0",
@ -7535,6 +7962,20 @@
] ]
], ],
"enum": null "enum": null
},
"digest": {
"description": "SHA256 hex digest of the blocked domain",
"field_type": "str",
"field_subtype": null,
"is_optional": false,
"is_nullable": true,
"version_history": [
[
"4.3.0",
"added"
]
],
"enum": null
} }
} }
}, },
@ -8347,7 +8788,7 @@
{ {
"name": "Account creation error", "name": "Account creation error",
"python_name": "AccountCreationError", "python_name": "AccountCreationError",
"func_call": "mastodon.create_account('halcy', 'secret', 'invalid email lol', True, return_detailed_error=True)", "func_call": "mastodon.create_account('halcy', 'secret', 'invalid email lol', True, return_detailed_error=True)[1]",
"func_call_real": null, "func_call_real": null,
"func_call_additional": null, "func_call_additional": null,
"func_alternate_acc": null, "func_alternate_acc": null,
@ -8380,7 +8821,7 @@
] ]
], ],
"field_type": "AccountCreationErrorDetails", "field_type": "AccountCreationErrorDetails",
"field_subtype": null, "field_subtype": "null",
"field_structuretype": null, "field_structuretype": null,
"is_optional": false, "is_optional": false,
"is_nullable": false "is_nullable": false
@ -8407,8 +8848,8 @@
"added" "added"
] ]
], ],
"field_type": "AccountCreationErrorDetailsField", "field_type": "EntityList",
"field_subtype": null, "field_subtype": "AccountCreationErrorDetailsField",
"field_structuretype": null, "field_structuretype": null,
"is_optional": true, "is_optional": true,
"is_nullable": false "is_nullable": false
@ -8422,8 +8863,8 @@
"added" "added"
] ]
], ],
"field_type": "AccountCreationErrorDetailsField", "field_type": "EntityList",
"field_subtype": null, "field_subtype": "AccountCreationErrorDetailsField",
"field_structuretype": null, "field_structuretype": null,
"is_optional": true, "is_optional": true,
"is_nullable": false "is_nullable": false
@ -8437,8 +8878,8 @@
"added" "added"
] ]
], ],
"field_type": "AccountCreationErrorDetailsField", "field_type": "EntityList",
"field_subtype": null, "field_subtype": "AccountCreationErrorDetailsField",
"field_structuretype": null, "field_structuretype": null,
"is_optional": true, "is_optional": true,
"is_nullable": false "is_nullable": false
@ -8452,8 +8893,8 @@
"added" "added"
] ]
], ],
"field_type": "AccountCreationErrorDetailsField", "field_type": "EntityList",
"field_subtype": null, "field_subtype": "AccountCreationErrorDetailsField",
"field_structuretype": null, "field_structuretype": null,
"is_optional": true, "is_optional": true,
"is_nullable": false "is_nullable": false
@ -8467,8 +8908,8 @@
"added" "added"
] ]
], ],
"field_type": "AccountCreationErrorDetailsField", "field_type": "EntityList",
"field_subtype": null, "field_subtype": "AccountCreationErrorDetailsField",
"field_structuretype": null, "field_structuretype": null,
"is_optional": true, "is_optional": true,
"is_nullable": false "is_nullable": false
@ -8482,8 +8923,8 @@
"added" "added"
] ]
], ],
"field_type": "AccountCreationErrorDetailsField", "field_type": "EntityList",
"field_subtype": null, "field_subtype": "AccountCreationErrorDetailsField",
"field_structuretype": null, "field_structuretype": null,
"is_optional": true, "is_optional": true,
"is_nullable": false "is_nullable": false
@ -8493,7 +8934,7 @@
{ {
"name": "Account creation error details field", "name": "Account creation error details field",
"python_name": "AccountCreationErrorDetailsField", "python_name": "AccountCreationErrorDetailsField",
"func_call": "mastodon.create_account('halcy', 'secret', 'invalid email lol', True).details.email", "func_call": "mastodon.create_account('halcy', 'secret', 'invalid email lol', True, return_detailed_error=True)[1].details.email[0]",
"func_call_real": null, "func_call_real": null,
"func_call_additional": null, "func_call_additional": null,
"func_alternate_acc": null, "func_alternate_acc": null,
@ -8544,4 +8985,4 @@
} }
} }
} }
] ]