aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2017-11-24 14:20:27 +0100
committerLorenz Diener <[email protected]>2017-11-24 14:20:27 +0100
commitcea4d4251a0b998ae734811ee78651d60a138d3e (patch)
treed65a8726cd7cb317b820970c8953740a39c46c82
parentfa53713abdb7e9fa1385186bd6649cc7317c7855 (diff)
downloadmastodon.py-cea4d4251a0b998ae734811ee78651d60a138d3e.tar.gz
Change exceptions slightly
-rw-r--r--mastodon/Mastodon.py9
-rw-r--r--mastodon/__init__.py4
-rw-r--r--mastodon/streaming.py15
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
1421class MastodonIllegalArgumentError(ValueError, MastodonError): 1421class 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
1429class MastodonFileNotFoundError(MastodonIOError): 1430class MastodonFileNotFoundError(MastodonIOError):
1431 """Raised when a file requested to be loaded can not be opened"""
1430 pass 1432 pass
1431 1433
1432 1434
1433class MastodonNetworkError(MastodonIOError): 1435class MastodonNetworkError(MastodonIOError):
1436 """Raised when network communication with the server fails"""
1434 pass 1437 pass
1435 1438
1436 1439
1437class MastodonAPIError(MastodonError): 1440class MastodonAPIError(MastodonError):
1441 """Raised when the mastodon API generates a response that cannot be handled"""
1438 pass 1442 pass
1439 1443
1440 1444
1441class MastodonRatelimitError(MastodonError): 1445class MastodonRatelimitError(MastodonError):
1446 """Raised when rate limiting is set to manual mode and the rate limit is exceeded"""
1447 pass
1448
1449class 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 @@
1from mastodon.Mastodon import Mastodon 1from mastodon.Mastodon import Mastodon
2from mastodon.streaming import StreamListener, MalformedEventError 2from 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
6import json 6import json
7import logging
8import six 7import six
9from mastodon import Mastodon 8from mastodon import Mastodon
10 9from mastodon.Mastodon import MastodonMalformedEventError
11log = logging.getLogger(__name__)
12
13class MalformedEventError(Exception):
14 """Raised when the server-sent event stream is malformed."""
15 pass
16
17 10
18class StreamListener(object): 11class 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
Powered by cgit v1.2.3 (git 2.41.0)