unbreak various things

pull/397/head
halcy 2025-02-14 01:50:47 +02:00
rodzic 4779af4ab3
commit 1867e13b88
3 zmienionych plików z 13 dodań i 2 usunięć

Wyświetl plik

@ -322,7 +322,8 @@ class Mastodon(Internals):
""" """
# Is the version > 4.4.0? Throw on trying to log in with password with a more informative message than the API error # Is the version > 4.4.0? Throw on trying to log in with password with a more informative message than the API error
if self.mastodon_major >= 4 and self.mastodon_minor >= 4 or self.mastodon_major > 4: if self.mastodon_major >= 4 and self.mastodon_minor >= 4 or self.mastodon_major > 4:
raise MastodonIllegalArgumentError('Password flow is no longer supported in Mastodon 4.4.0 and later.') if password is not None:
raise MastodonIllegalArgumentError('Password flow is no longer supported in Mastodon 4.4.0 and later.')
if username is not None and password is not None: if username is not None and password is not None:
params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token']) params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token'])

Wyświetl plik

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

Wyświetl plik

@ -103,6 +103,14 @@ class StreamListener(object):
useful to carry out periodic housekeeping tasks, or just to confirm useful to carry out periodic housekeeping tasks, or just to confirm
that the connection is still open.""" that the connection is still open."""
pass pass
def on_any_event(self, name, data):
"""A generic event handler that is called for every event received.
The name contains the event-name and data contains the content of the event.
Called before the more specific on_xxx handlers.
"""
pass
def handle_stream(self, response): def handle_stream(self, response):
""" """
@ -209,12 +217,14 @@ class StreamListener(object):
# The "for_stream" is right now only theoretical - it's only supported on websocket, # The "for_stream" is right now only theoretical - it's only supported on websocket,
# and we do not support websocket based multiplexed streams (yet). # and we do not support websocket based multiplexed streams (yet).
if "for_stream" in handler_args: if "for_stream" in handler_args:
self.on_any_event(name, payload, for_stream)
if handler != self.on_unknown_event: if handler != self.on_unknown_event:
handler(payload, for_stream) handler(payload, for_stream)
else: else:
handler(name, payload, for_stream) handler(name, payload, for_stream)
else: else:
if handler != self.on_unknown_event: if handler != self.on_unknown_event:
self.on_any_event(name, payload)
if handler == self.on_filters_changed: if handler == self.on_filters_changed:
handler() handler()
else: else:
@ -261,7 +271,6 @@ class CallbackStreamListener(StreamListener):
self.encryted_message_handler = encryted_message_handler self.encryted_message_handler = encryted_message_handler
def on_update(self, status): def on_update(self, status):
print("ONUPDATE", status)
if self.update_handler is not None: if self.update_handler is not None:
self.update_handler(status) self.update_handler(status)