diff options
-rw-r--r-- | mastodon/Mastodon.py | 9 | ||||
-rw-r--r-- | mastodon/__init__.py | 4 | ||||
-rw-r--r-- | mastodon/streaming.py | 15 |
3 files changed, 15 insertions, 13 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index ab0071b..c35ad2d 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -1419,6 +1419,7 @@ class MastodonError(Exception): | |||
1419 | 1419 | ||
1420 | 1420 | ||
1421 | class MastodonIllegalArgumentError(ValueError, MastodonError): | 1421 | class MastodonIllegalArgumentError(ValueError, MastodonError): |
1422 | """Raised when an incorrect parameter is passed to a function""" | ||
1422 | pass | 1423 | pass |
1423 | 1424 | ||
1424 | 1425 | ||
@@ -1427,16 +1428,24 @@ class MastodonIOError(IOError, MastodonError): | |||
1427 | 1428 | ||
1428 | 1429 | ||
1429 | class MastodonFileNotFoundError(MastodonIOError): | 1430 | class MastodonFileNotFoundError(MastodonIOError): |
1431 | """Raised when a file requested to be loaded can not be opened""" | ||
1430 | pass | 1432 | pass |
1431 | 1433 | ||
1432 | 1434 | ||
1433 | class MastodonNetworkError(MastodonIOError): | 1435 | class MastodonNetworkError(MastodonIOError): |
1436 | """Raised when network communication with the server fails""" | ||
1434 | pass | 1437 | pass |
1435 | 1438 | ||
1436 | 1439 | ||
1437 | class MastodonAPIError(MastodonError): | 1440 | class MastodonAPIError(MastodonError): |
1441 | """Raised when the mastodon API generates a response that cannot be handled""" | ||
1438 | pass | 1442 | pass |
1439 | 1443 | ||
1440 | 1444 | ||
1441 | class MastodonRatelimitError(MastodonError): | 1445 | class MastodonRatelimitError(MastodonError): |
1446 | """Raised when rate limiting is set to manual mode and the rate limit is exceeded""" | ||
1447 | pass | ||
1448 | |||
1449 | class MastodonMalformedEventError(MastodonError): | ||
1450 | """Raised when the server-sent event stream is malformed""" | ||
1442 | pass | 1451 | pass |
diff --git a/mastodon/__init__.py b/mastodon/__init__.py index 9c8e39b..3123356 100644 --- a/mastodon/__init__.py +++ b/mastodon/__init__.py | |||
@@ -1,4 +1,4 @@ | |||
1 | from mastodon.Mastodon import Mastodon | 1 | from mastodon.Mastodon import Mastodon |
2 | from mastodon.streaming import StreamListener, MalformedEventError | 2 | from mastodon.streaming import StreamListener |
3 | 3 | ||
4 | __all__ = ['Mastodon', 'StreamListener', 'MalformedEventError'] | 4 | __all__ = ['Mastodon', 'StreamListener'] |
diff --git a/mastodon/streaming.py b/mastodon/streaming.py index c202ff6..cac2456 100644 --- a/mastodon/streaming.py +++ b/mastodon/streaming.py | |||
@@ -4,16 +4,9 @@ https://github.com/tootsuite/mastodon/blob/master/docs/Using-the-API/Streaming-A | |||
4 | """ | 4 | """ |
5 | 5 | ||
6 | import json | 6 | import json |
7 | import logging | ||
8 | import six | 7 | import six |
9 | from mastodon import Mastodon | 8 | from mastodon import Mastodon |
10 | 9 | from mastodon.Mastodon import MastodonMalformedEventError | |
11 | log = logging.getLogger(__name__) | ||
12 | |||
13 | class MalformedEventError(Exception): | ||
14 | """Raised when the server-sent event stream is malformed.""" | ||
15 | pass | ||
16 | |||
17 | 10 | ||
18 | class StreamListener(object): | 11 | class StreamListener(object): |
19 | """Callbacks for the streaming API. Create a subclass, override the on_xxx | 12 | """Callbacks for the streaming API. Create a subclass, override the on_xxx |
@@ -55,7 +48,7 @@ class StreamListener(object): | |||
55 | line = raw_line.decode('utf-8') | 48 | line = raw_line.decode('utf-8') |
56 | except UnicodeDecodeError as err: | 49 | except UnicodeDecodeError as err: |
57 | six.raise_from( | 50 | six.raise_from( |
58 | MalformedEventError("Malformed UTF-8", line), | 51 | MastodonMalformedEventError("Malformed UTF-8", line), |
59 | err | 52 | err |
60 | ) | 53 | ) |
61 | 54 | ||
@@ -85,14 +78,14 @@ class StreamListener(object): | |||
85 | payload = json.loads(data, object_hook = Mastodon._Mastodon__json_hooks) | 78 | payload = json.loads(data, object_hook = Mastodon._Mastodon__json_hooks) |
86 | except KeyError as err: | 79 | except KeyError as err: |
87 | six.raise_from( | 80 | six.raise_from( |
88 | MalformedEventError('Missing field', err.args[0], event), | 81 | MastodonMalformedEventError('Missing field', err.args[0], event), |
89 | err | 82 | err |
90 | ) | 83 | ) |
91 | except ValueError as err: | 84 | except ValueError as err: |
92 | # py2: plain ValueError | 85 | # py2: plain ValueError |
93 | # py3: json.JSONDecodeError, a subclass of ValueError | 86 | # py3: json.JSONDecodeError, a subclass of ValueError |
94 | six.raise_from( | 87 | six.raise_from( |
95 | MalformedEventError('Bad JSON', data), | 88 | MastodonMalformedEventError('Bad JSON', data), |
96 | err | 89 | err |
97 | ) | 90 | ) |
98 | 91 | ||