diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 4 | ||||
-rw-r--r-- | mastodon/streaming.py | 11 |
2 files changed, 12 insertions, 3 deletions
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): | |||
1872 | """Raised when network communication with the server fails""" | 1872 | """Raised when network communication with the server fails""" |
1873 | pass | 1873 | pass |
1874 | 1874 | ||
1875 | class MastodonReadTimeout(MastodonNetworkError): | ||
1876 | """Raised when a stream times out""" | ||
1877 | pass | ||
1878 | |||
1875 | 1879 | ||
1876 | class MastodonAPIError(MastodonError): | 1880 | class MastodonAPIError(MastodonError): |
1877 | """Raised when the mastodon API generates a response that cannot be handled""" | 1881 | """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 | |||
6 | import json | 6 | import json |
7 | import six | 7 | import six |
8 | from mastodon import Mastodon | 8 | from mastodon import Mastodon |
9 | from mastodon.Mastodon import MastodonMalformedEventError, MastodonNetworkError | 9 | from mastodon.Mastodon import MastodonMalformedEventError, MastodonNetworkError, MastodonReadTimeout |
10 | from requests.exceptions import ChunkedEncodingError | 10 | from requests.exceptions import ChunkedEncodingError, ReadTimeout |
11 | 11 | ||
12 | class StreamListener(object): | 12 | class StreamListener(object): |
13 | """Callbacks for the streaming API. Create a subclass, override the on_xxx | 13 | """Callbacks for the streaming API. Create a subclass, override the on_xxx |
@@ -68,7 +68,12 @@ class StreamListener(object): | |||
68 | MastodonNetworkError("Server ceased communication."), | 68 | MastodonNetworkError("Server ceased communication."), |
69 | err | 69 | err |
70 | ) | 70 | ) |
71 | 71 | except MastodonReadTimeout as err: | |
72 | six.raise_from( | ||
73 | MastodonReadTimeout("Timed out while reading from server."), | ||
74 | err | ||
75 | ) | ||
76 | |||
72 | def _parse_line(self, line, event): | 77 | def _parse_line(self, line, event): |
73 | if line.startswith(':'): | 78 | if line.startswith(':'): |
74 | self.handle_heartbeat() | 79 | self.handle_heartbeat() |