diff options
author | Aljoscha Rittner <[email protected]> | 2022-06-24 18:11:23 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2022-06-24 18:11:23 +0200 |
commit | c7fdcf3faec29040d32b5a9afa81859cc2195d99 (patch) | |
tree | 5f7c2a66e063b80e77b7be1fe2c24be986e70e1d /docs | |
parent | c9008a1cdcd31ba47c10d7b6f35cc7aceffe81f5 (diff) | |
parent | a987af8a0d20db59f1531492e2313ac8cce81f48 (diff) | |
download | mastodon.py-c7fdcf3faec29040d32b5a9afa81859cc2195d99.tar.gz |
Merge pull request #235 from arittner/stream-unknown-handler
Support of processing unknown events and event names with dots.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/index.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/index.rst b/docs/index.rst index 473777a..e7b1ed9 100644 --- a/docs/index.rst +++ b/docs/index.rst | |||
@@ -1275,6 +1275,19 @@ The streaming functions take instances of `StreamListener` as the `listener` par | |||
1275 | A `CallbackStreamListener` class that allows you to specify function callbacks | 1275 | A `CallbackStreamListener` class that allows you to specify function callbacks |
1276 | directly is included for convenience. | 1276 | directly is included for convenience. |
1277 | 1277 | ||
1278 | For new well-known events implement the streaming function in `StreamListener` or `CallbackStreamListener`. | ||
1279 | The function name is `on_` + the event name. If the event-name contains dots, use an underscore instead. | ||
1280 | |||
1281 | E.g. for `'status.update'` the listener function should be named as `on_status_update`. | ||
1282 | |||
1283 | It may be that future Mastodon versions will come with completely new (unknown) event names. In this | ||
1284 | case a (deprecated) Mastodon.py would throw an error. If you want to avoid this in general, you can | ||
1285 | override the listener function `on_unknown_event`. This has an additional parameter `name` which informs | ||
1286 | about the name of the event. `unknown_event` contains the content of the event. | ||
1287 | |||
1288 | Alternatively, a callback function can be passed in the `unknown_event_handler` parameter in the | ||
1289 | `CallbackStreamListener` constructor. | ||
1290 | |||
1278 | When in not-async mode or async mode without async_reconnect, the stream functions may raise | 1291 | When in not-async mode or async mode without async_reconnect, the stream functions may raise |
1279 | various exceptions: `MastodonMalformedEventError` if a received event cannot be parsed and | 1292 | various exceptions: `MastodonMalformedEventError` if a received event cannot be parsed and |
1280 | `MastodonNetworkError` if any connection problems occur. | 1293 | `MastodonNetworkError` if any connection problems occur. |
@@ -1294,6 +1307,7 @@ StreamListener | |||
1294 | .. automethod:: StreamListener.on_notification | 1307 | .. automethod:: StreamListener.on_notification |
1295 | .. automethod:: StreamListener.on_delete | 1308 | .. automethod:: StreamListener.on_delete |
1296 | .. automethod:: StreamListener.on_conversation | 1309 | .. automethod:: StreamListener.on_conversation |
1310 | .. automethod:: StreamListener.on_unknown_event | ||
1297 | .. automethod:: StreamListener.on_abort | 1311 | .. automethod:: StreamListener.on_abort |
1298 | .. automethod:: StreamListener.handle_heartbeat | 1312 | .. automethod:: StreamListener.handle_heartbeat |
1299 | 1313 | ||