From 06e32c14bcb5a1ef1a5e618a1b413ea011416c9d Mon Sep 17 00:00:00 2001 From: codl Date: Thu, 19 Apr 2018 17:10:42 +0200 Subject: raise MastodonReadTimeout when a stream times out --- mastodon/Mastodon.py | 4 ++++ mastodon/streaming.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 5461661..49597ca 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1872,6 +1872,10 @@ class MastodonNetworkError(MastodonIOError): """Raised when network communication with the server fails""" pass +class MastodonReadTimeout(MastodonNetworkError): + """Raised when a stream times out""" + pass + class MastodonAPIError(MastodonError): """Raised when the mastodon API generates a response that cannot be handled""" diff --git a/mastodon/streaming.py b/mastodon/streaming.py index 1c73f48..3fbd569 100644 --- a/mastodon/streaming.py +++ b/mastodon/streaming.py @@ -6,8 +6,8 @@ https://github.com/tootsuite/mastodon/blob/master/docs/Using-the-API/Streaming-A import json import six from mastodon import Mastodon -from mastodon.Mastodon import MastodonMalformedEventError, MastodonNetworkError -from requests.exceptions import ChunkedEncodingError +from mastodon.Mastodon import MastodonMalformedEventError, MastodonNetworkError, MastodonReadTimeout +from requests.exceptions import ChunkedEncodingError, ReadTimeout class StreamListener(object): """Callbacks for the streaming API. Create a subclass, override the on_xxx @@ -68,7 +68,12 @@ class StreamListener(object): MastodonNetworkError("Server ceased communication."), err ) - + except MastodonReadTimeout as err: + six.raise_from( + MastodonReadTimeout("Timed out while reading from server."), + err + ) + def _parse_line(self, line, event): if line.startswith(':'): self.handle_heartbeat() -- cgit v1.2.3