aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/streaming.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/mastodon/streaming.py b/mastodon/streaming.py
index 2080908..e43d7d6 100644
--- a/mastodon/streaming.py
+++ b/mastodon/streaming.py
@@ -59,13 +59,9 @@ class StreamListener(object):
59 def on_unknown_event(self, name, unknown_event=None): 59 def on_unknown_event(self, name, unknown_event=None):
60 """An unknown mastodon API event has been received. The name contains the event-name and unknown_event 60 """An unknown mastodon API event has been received. The name contains the event-name and unknown_event
61 contains the content of the unknown event. 61 contains the content of the unknown event.
62
63 This function must be implemented, if unknown events should be handled without an error.
64 """ 62 """
65 exception = MastodonMalformedEventError('Bad event type', name) 63 pass
66 self.on_abort(exception) 64
67 raise exception
68
69 def handle_heartbeat(self): 65 def handle_heartbeat(self):
70 """The server has sent us a keep-alive message. This callback may be 66 """The server has sent us a keep-alive message. This callback may be
71 useful to carry out periodic housekeeping tasks, or just to confirm 67 useful to carry out periodic housekeeping tasks, or just to confirm
@@ -171,6 +167,7 @@ class StreamListener(object):
171 exception, 167 exception,
172 err 168 err
173 ) 169 )
170
174 # New mastodon API also supports event names with dots, 171 # New mastodon API also supports event names with dots,
175 # specifically, status_update. 172 # specifically, status_update.
176 handler_name = 'on_' + name.replace('.', '_') 173 handler_name = 'on_' + name.replace('.', '_')
@@ -200,8 +197,9 @@ class CallbackStreamListener(StreamListener):
200 """ 197 """
201 Simple callback stream handler class. 198 Simple callback stream handler class.
202 Can optionally additionally send local update events to a separate handler. 199 Can optionally additionally send local update events to a separate handler.
203 Define an unknown_event_handler for new Mastodon API events. If not, the 200 Define an unknown_event_handler for new Mastodon API events. This handler is
204 listener will raise an error on new, not handled, events from the API. 201 *not* guaranteed to receive these events forever, and should only be used
202 for diagnostics.
205 """ 203 """
206 204
207 def __init__(self, update_handler=None, local_update_handler=None, delete_handler=None, notification_handler=None, conversation_handler=None, unknown_event_handler=None, status_update_handler=None): 205 def __init__(self, update_handler=None, local_update_handler=None, delete_handler=None, notification_handler=None, conversation_handler=None, unknown_event_handler=None, status_update_handler=None):
@@ -242,10 +240,6 @@ class CallbackStreamListener(StreamListener):
242 def on_unknown_event(self, name, unknown_event=None): 240 def on_unknown_event(self, name, unknown_event=None):
243 if self.unknown_event_handler != None: 241 if self.unknown_event_handler != None:
244 self.unknown_event_handler(name, unknown_event) 242 self.unknown_event_handler(name, unknown_event)
245 else:
246 exception = MastodonMalformedEventError('Bad event type', name)
247 self.on_abort(exception)
248 raise exception
249 243
250 def on_status_update(self, status): 244 def on_status_update(self, status):
251 if self.status_update_handler != None: 245 if self.status_update_handler != None:
Powered by cgit v1.2.3 (git 2.41.0)