From cea4d4251a0b998ae734811ee78651d60a138d3e Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Fri, 24 Nov 2017 14:20:27 +0100 Subject: Change exceptions slightly --- mastodon/Mastodon.py | 9 +++++++++ mastodon/__init__.py | 4 ++-- 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): class MastodonIllegalArgumentError(ValueError, MastodonError): + """Raised when an incorrect parameter is passed to a function""" pass @@ -1427,16 +1428,24 @@ class MastodonIOError(IOError, MastodonError): class MastodonFileNotFoundError(MastodonIOError): + """Raised when a file requested to be loaded can not be opened""" pass class MastodonNetworkError(MastodonIOError): + """Raised when network communication with the server fails""" pass class MastodonAPIError(MastodonError): + """Raised when the mastodon API generates a response that cannot be handled""" pass class MastodonRatelimitError(MastodonError): + """Raised when rate limiting is set to manual mode and the rate limit is exceeded""" + pass + +class MastodonMalformedEventError(MastodonError): + """Raised when the server-sent event stream is malformed""" 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 @@ from mastodon.Mastodon import Mastodon -from mastodon.streaming import StreamListener, MalformedEventError +from mastodon.streaming import StreamListener -__all__ = ['Mastodon', 'StreamListener', 'MalformedEventError'] +__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 """ import json -import logging import six from mastodon import Mastodon - -log = logging.getLogger(__name__) - -class MalformedEventError(Exception): - """Raised when the server-sent event stream is malformed.""" - pass - +from mastodon.Mastodon import MastodonMalformedEventError class StreamListener(object): """Callbacks for the streaming API. Create a subclass, override the on_xxx @@ -55,7 +48,7 @@ class StreamListener(object): line = raw_line.decode('utf-8') except UnicodeDecodeError as err: six.raise_from( - MalformedEventError("Malformed UTF-8", line), + MastodonMalformedEventError("Malformed UTF-8", line), err ) @@ -85,14 +78,14 @@ class StreamListener(object): payload = json.loads(data, object_hook = Mastodon._Mastodon__json_hooks) except KeyError as err: six.raise_from( - MalformedEventError('Missing field', err.args[0], event), + MastodonMalformedEventError('Missing field', err.args[0], event), err ) except ValueError as err: # py2: plain ValueError # py3: json.JSONDecodeError, a subclass of ValueError six.raise_from( - MalformedEventError('Bad JSON', data), + MastodonMalformedEventError('Bad JSON', data), err ) -- cgit v1.2.3