From b663394c6da1dee2069be6549deed0012d5f0285 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Mon, 4 Jun 2018 17:58:11 +0200 Subject: Streaming error handler --- DEVELOPMENT.md | 1 + docs/index.rst | 1 + mastodon/streaming.py | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index d52ce46..55070ac 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -4,6 +4,7 @@ Here's some general stuff to keep in mind, and some work that needs to be done use requests over urllib, et cetera. * Current TODOs: + * Stream since_id and better resume * Testing - test 2.3 stuff and verify it works, test pinning * 2.4 support: * Dict updates (bot flag, profile meta fields, ...?) diff --git a/docs/index.rst b/docs/index.rst index 55d4495..85b4b60 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -227,6 +227,7 @@ User dicts # from account_verify_credentials() 'moved_to_account': # If set, an account dict of the account this user has # set up as their moved-to address. + 'bot': # Boolean indicating whether this account is automated. } mastodon.account_verify_credentials()["source"] diff --git a/mastodon/streaming.py b/mastodon/streaming.py index 3fbd569..416f271 100644 --- a/mastodon/streaming.py +++ b/mastodon/streaming.py @@ -25,6 +25,11 @@ class StreamListener(object): describing the notification.""" pass + def on_abort(self): + """Some error happened that requires that the connection should + be aborted (or re-established)""" + pass + def on_delete(self, status_id): """A status has been deleted. status_id is the status' integer ID.""" pass @@ -64,11 +69,13 @@ class StreamListener(object): else: line_buffer.extend(chunk) except ChunkedEncodingError as err: + self.on_abort() six.raise_from( MastodonNetworkError("Server ceased communication."), err ) except MastodonReadTimeout as err: + self.on_abort() six.raise_from( MastodonReadTimeout("Timed out while reading from server."), err -- cgit v1.2.3