From 1867e13b8819187b4c037376a3f05b68c5225a22 Mon Sep 17 00:00:00 2001 From: halcy Date: Fri, 14 Feb 2025 01:50:47 +0200 Subject: [PATCH] unbreak various things --- mastodon/authentication.py | 3 ++- mastodon/internals.py | 1 + mastodon/streaming.py | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mastodon/authentication.py b/mastodon/authentication.py index 4c96061..bb0f9da 100644 --- a/mastodon/authentication.py +++ b/mastodon/authentication.py @@ -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 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: params = self.__generate_params(locals(), ['scopes', 'to_file', 'code', 'refresh_token']) diff --git a/mastodon/internals.py b/mastodon/internals.py index 567f701..1bba642 100644 --- a/mastodon/internals.py +++ b/mastodon/internals.py @@ -21,6 +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.return_types import AttribAccessDict, PaginatableList, try_cast_recurse from mastodon.return_types import * ### diff --git a/mastodon/streaming.py b/mastodon/streaming.py index c4f8f74..62aa6f3 100644 --- a/mastodon/streaming.py +++ b/mastodon/streaming.py @@ -103,6 +103,14 @@ class StreamListener(object): useful to carry out periodic housekeeping tasks, or just to confirm that the connection is still open.""" 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): """ @@ -209,12 +217,14 @@ class StreamListener(object): # The "for_stream" is right now only theoretical - it's only supported on websocket, # and we do not support websocket based multiplexed streams (yet). if "for_stream" in handler_args: + self.on_any_event(name, payload, for_stream) if handler != self.on_unknown_event: handler(payload, for_stream) else: handler(name, payload, for_stream) else: if handler != self.on_unknown_event: + self.on_any_event(name, payload) if handler == self.on_filters_changed: handler() else: @@ -261,7 +271,6 @@ class CallbackStreamListener(StreamListener): self.encryted_message_handler = encryted_message_handler def on_update(self, status): - print("ONUPDATE", status) if self.update_handler is not None: self.update_handler(status)