refactor some stuff to rename types, since that shadows a functools module, and update docs

pull/397/head
halcy 2025-02-14 01:14:07 +02:00
rodzic 3e78acb406
commit 8f563d5e60
30 zmienionych plików z 48 dodań i 5325 usunięć

Wyświetl plik

@ -16,6 +16,7 @@ v2.0.0 (IN PROGRESS)
* Added CITATION.cff (Thanks @hauschke for the suggestion)
* Fixed a potential issue with modification to locals (Thanks Konano)
* Added support for 4.3.0 `accounts` endpoint (Thanks AlexKalopsia)
* Fix version parsing for GoToSocial (Thanks gmemstr)
v1.8.1
------

Wyświetl plik

@ -19,20 +19,29 @@ Register your app! This only needs to be done once (per server, or when distribu
)
'''
Then, log in. This can be done every time your application starts (e.g. when writing a simple bot), or you can use the persisted information:
Then, log in. This can be done every time your application starts, or you can use the persisted information:
.. code-block:: python
from mastodon import Mastodon
mastodon = Mastodon(client_id = 'pytooter_clientcred.secret',)
print(mastodon.auth_request_url())
# open the URL in the browser and paste the code you get
mastodon.log_in(
'my_login_email@example.com',
'incrediblygoodpassword',
to_file = 'pytooter_usercred.secret'
code=input("Enter the OAuth authorization code: "),
to_file="pytooter_usercred.secret"
)
Note that this won't work when using 2FA - you'll have to use OAuth, in that case. To post, create an actual API instance:
Note that previous versions of Mastodon allowed logging in with username and
password - unfortunately, due to security concerns, Mastodon has started
requiring OAuth starting with version 4.4.0. If you're building a bot, you
may with to instead just generate a token in the UI (On Mastodon:
your-server.com/settings/applications) and use it directly
To post, create an actual API instance:
.. code-block:: python

Wyświetl plik

@ -25,7 +25,7 @@ from mastodon.compat import urlparse
from mastodon.utility import parse_version_string, max_version, api_version
from mastodon.utility import Mastodon as MastoUtility
from mastodon.types import *
from mastodon.return_types import *
from mastodon.errors import *
from mastodon.versions import _DICT_VERSION_APPLICATION, _DICT_VERSION_MENTION, _DICT_VERSION_MEDIA, _DICT_VERSION_ACCOUNT, _DICT_VERSION_POLL, \

Wyświetl plik

@ -10,7 +10,7 @@ from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from typing import Union, Optional, Tuple, List
from mastodon.types import AccountCreationError, Account, IdType, Status, PaginatableList, NonPaginatableList, UserList, Relationship, FamiliarFollowers, Tag, IdType, PathOrFile, AttribAccessDict, try_cast
from mastodon.return_types import AccountCreationError, Account, IdType, Status, PaginatableList, NonPaginatableList, UserList, Relationship, FamiliarFollowers, Tag, IdType, PathOrFile, AttribAccessDict, try_cast
from datetime import datetime
class Mastodon(Internals):

Wyświetl plik

@ -7,7 +7,7 @@ from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from typing import Optional, List, Union
from mastodon.types import IdType, PrimitiveIdType, Account, AdminAccount, AdminReport, PaginatableList, NonPaginatableList, Status, Tag,\
from mastodon.return_types import IdType, PrimitiveIdType, Account, AdminAccount, AdminReport, PaginatableList, NonPaginatableList, Status, Tag,\
PreviewCard, AdminDomainBlock, AdminMeasure, AdminDimension, AdminRetention
from datetime import datetime

Wyświetl plik

@ -15,7 +15,7 @@ from mastodon.utility import parse_version_string, api_version
from mastodon.internals import Mastodon as Internals
from mastodon.utility import Mastodon as Utility
from typing import List, Optional, Union, Tuple
from mastodon.types import Application
from mastodon.return_types import Application
from mastodon.compat import PurePath
class Mastodon(Internals):
@ -312,9 +312,9 @@ class Mastodon(Internals):
generating the auth request URL. If passing `code`you should not pass `username` or `password`.
When using the password flow, the username is the email address used to log in into Mastodon.
Note that Mastodon has expressed that they intend to remove this login method - if you are currently
using it, please consider migrating to OAuth2 (or, for single-user bots, generating a token manually
via the web interface).
Note that Mastodon has removed this flow starting with 4.4.0, so it is unfortunately not
possible to log in in this way anymore. Please use either the code flow, or generate
a token from the web UI.
Can persist access token to file `to_file`, to be used in the constructor.

Wyświetl plik

@ -15,7 +15,7 @@ except:
IMPL_HAS_ECE = True
try:
import http_ece
import http_ece # type: ignore
except:
IMPL_HAS_ECE = False
http_ece = None
@ -30,7 +30,7 @@ except:
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from urlparse import urlparse # type: ignore
try:
import magic

Wyświetl plik

@ -5,7 +5,7 @@ from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from typing import Union, Optional
from mastodon.types import IdType, PaginatableList, Conversation
from mastodon.return_types import IdType, PaginatableList, Conversation
class Mastodon(Internals):
###

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_ACCOUNT
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Account, NonPaginatableList
from mastodon.return_types import Account, NonPaginatableList
class Mastodon(Internals):
###

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_STATUS
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Status, IdType, PaginatableList
from mastodon.return_types import Status, IdType, PaginatableList
from typing import Optional, Union

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_FEATURED_TAG, _DICT_VERSION_HASHTAG
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Tag, NonPaginatableList, PaginatableList, FeaturedTag, IdType
from mastodon.return_types import Tag, NonPaginatableList, PaginatableList, FeaturedTag, IdType
from mastodon.errors import MastodonIllegalArgumentError
from typing import Union, Optional

Wyświetl plik

@ -6,7 +6,7 @@ from mastodon.utility import api_version
from mastodon.compat import urlparse
from mastodon.internals import Mastodon as Internals
from mastodon.types import Instance, InstanceV2, NonPaginatableList, Activity, Nodeinfo, AttribAccessDict, Rule, Announcement, CustomEmoji, Account, IdType
from mastodon.return_types import Instance, InstanceV2, NonPaginatableList, Activity, Nodeinfo, AttribAccessDict, Rule, Announcement, CustomEmoji, Account, IdType
from typing import Union, Optional

Wyświetl plik

@ -21,8 +21,7 @@ from mastodon.errors import MastodonNetworkError, MastodonIllegalArgumentError,
MastodonGatewayTimeoutError, MastodonServerError, MastodonAPIError, MastodonMalformedEventError
from mastodon.compat import urlparse, magic, PurePath, Path
from mastodon.defaults import _DEFAULT_STREAM_TIMEOUT, _DEFAULT_STREAM_RECONNECT_WAIT_SEC
from mastodon.types import AttribAccessDict, PaginatableList, try_cast_recurse
from mastodon.types import *
from mastodon.return_types import *
###
# Internal helpers, dragons probably

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_LIST, _DICT_VERSION_ACCOUNT
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import NonPaginatableList, UserList, IdType, PaginatableList, Account
from mastodon.return_types import NonPaginatableList, UserList, IdType, PaginatableList, Account
from typing import List, Union, Optional

Wyświetl plik

@ -7,7 +7,7 @@ from mastodon.errors import MastodonVersionError, MastodonAPIError
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import MediaAttachment, PathOrFile, IdType
from mastodon.return_types import MediaAttachment, PathOrFile, IdType
from typing import Optional, Union, Tuple, List, Dict, Any

Wyświetl plik

@ -5,7 +5,7 @@ from mastodon.errors import MastodonIllegalArgumentError
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Notification, IdType, PaginatableList, Account
from mastodon.return_types import Notification, IdType, PaginatableList, Account
from typing import Union, Optional, List
class Mastodon(Internals):

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_POLL
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Poll, IdType
from mastodon.return_types import Poll, IdType
from typing import Union, List
class Mastodon(Internals):

Wyświetl plik

@ -7,7 +7,7 @@ from mastodon.errors import MastodonIllegalArgumentError
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Preferences, Marker, Status, IdType
from mastodon.return_types import Preferences, Marker, Status, IdType
from typing import Union, List, Dict
class Mastodon(Internals):

Wyświetl plik

@ -11,7 +11,7 @@ from mastodon.compat import IMPL_HAS_CRYPTO, ec, serialization, default_backend
from mastodon.compat import IMPL_HAS_ECE, http_ece
from mastodon.internals import Mastodon as Internals
from mastodon.types import WebpushCryptoParamsPubkey, WebpushCryptoParamsPrivkey, WebPushSubscription, PushNotification, try_cast_recurse
from mastodon.return_types import WebpushCryptoParamsPubkey, WebpushCryptoParamsPrivkey, WebPushSubscription, PushNotification, try_cast_recurse
from typing import Optional, Tuple
class Mastodon(Internals):

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_ACCOUNT, _DICT_VERSION_RELATIONSHIP
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Account, Relationship, PaginatableList, IdType
from mastodon.return_types import Account, Relationship, PaginatableList, IdType
from typing import Optional, Union
class Mastodon(Internals):

Wyświetl plik

@ -6,7 +6,7 @@ from mastodon.errors import MastodonVersionError, MastodonIllegalArgumentError
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import NonPaginatableList, Report, Account, IdType, Status, Rule
from mastodon.return_types import NonPaginatableList, Report, Account, IdType, Status, Rule
from typing import Union, Optional, List
class Mastodon(Internals):

Wyświetl plik

@ -5,7 +5,7 @@ from mastodon.errors import MastodonVersionError
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Search, SearchV2, Account, IdType
from mastodon.return_types import Search, SearchV2, Account, IdType
from typing import Union, Optional
class Mastodon(Internals):

Wyświetl plik

@ -9,7 +9,7 @@ from mastodon.errors import MastodonIllegalArgumentError
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Status, IdType, ScheduledStatus, PreviewCard, Context, NonPaginatableList, Account,\
from mastodon.return_types import Status, IdType, ScheduledStatus, PreviewCard, Context, NonPaginatableList, Account,\
MediaAttachment, Poll, StatusSource, StatusEdit, PaginatableList
from typing import Union, Optional, List

Wyświetl plik

@ -11,7 +11,7 @@ except:
from mastodon import Mastodon
from mastodon.Mastodon import MastodonMalformedEventError, MastodonNetworkError, MastodonReadTimeout
from mastodon.types import AttribAccessDict, Status, Notification, IdType, Conversation, Announcement, StreamReaction, try_cast_recurse
from mastodon.return_types import AttribAccessDict, Status, Notification, IdType, Conversation, Announcement, StreamReaction, try_cast_recurse
from requests.exceptions import ChunkedEncodingError, ReadTimeout, ConnectionError

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_ACCOUNT
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import NonPaginatableList, Account, IdType, Suggestion
from mastodon.return_types import NonPaginatableList, Account, IdType, Suggestion
from typing import Union
class Mastodon(Internals):

Wyświetl plik

@ -5,7 +5,7 @@ from mastodon.errors import MastodonIllegalArgumentError, MastodonNotFoundError
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Status, IdType, PaginatableList, UserList
from mastodon.return_types import Status, IdType, PaginatableList, UserList
from typing import Union, Optional
from datetime import datetime

Wyświetl plik

@ -4,7 +4,7 @@ from mastodon.versions import _DICT_VERSION_HASHTAG, _DICT_VERSION_STATUS, _DICT
from mastodon.utility import api_version
from mastodon.internals import Mastodon as Internals
from mastodon.types import Tag, Status, PreviewCard, NonPaginatableList
from mastodon.return_types import Tag, Status, PreviewCard, NonPaginatableList
from typing import Optional, Union
class Mastodon(Internals):

Plik diff jest za duży Load Diff

Wyświetl plik

@ -142,7 +142,7 @@ if sys.version_info < (3, 9):
def resolve_type(t):
# I'm sorry about this, but I cannot think of another way to make this work properly in versions below 3.9 that
# cannot resolve forward references in a sane way
from mastodon.types import Account, AccountField, Role, CredentialAccountSource, Status, StatusEdit, FilterResult,\
from mastodon.return_types import Account, AccountField, Role, CredentialAccountSource, Status, StatusEdit, FilterResult,\
StatusMention, ScheduledStatus, ScheduledStatusParams, Poll, PollOption, Conversation, Tag, TagHistory, CustomEmoji,\
Application, Relationship, Filter, FilterV2, Notification, Context, UserList, MediaAttachment, MediaAttachmentMetadataContainer,\
MediaAttachmentImageMetadata, MediaAttachmentVideoMetadata, MediaAttachmentAudioMetadata, MediaAttachmentFocusPoint, MediaAttachmentColors, \
@ -292,7 +292,7 @@ def try_cast_recurse(t, value, union_specializer=None):
elif orig_type is Union:
real_type = None
if union_specializer is not None:
from mastodon.types import MediaAttachmentImageMetadata, MediaAttachmentVideoMetadata, MediaAttachmentAudioMetadata
from mastodon.return_types import MediaAttachmentImageMetadata, MediaAttachmentVideoMetadata, MediaAttachmentAudioMetadata
real_type = {
"image": MediaAttachmentImageMetadata,
"video": MediaAttachmentVideoMetadata,
@ -466,7 +466,7 @@ class AttribAccessDict(OrderedStrDict):
# 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
from return_types import MediaAttachment
if type(self) == MediaAttachment and key == "type":
self.__union_specializer = val

Wyświetl plik

@ -12,7 +12,7 @@ from mastodon.internals import Mastodon as Internals
from mastodon.versions import parse_version_string, max_version, api_version
from typing import Optional
from mastodon.types import PaginatableList, PaginationInfo
from mastodon.return_types import PaginatableList, PaginationInfo
# Class level:
class Mastodon(Internals):