Skip to content

Commit

Permalink
Harmonize exceptions names with Error suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
mlorant committed Oct 4, 2017
1 parent 36a58fa commit 8631bb1
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion doc/src/api.rst
Expand Up @@ -22,7 +22,7 @@ IMAPClient wraps exceptions raised by imaplib to ease the error handling.
All the exceptions related to IMAP errors are defined in the module
`imapclient.exceptions`. The following general exceptions may be raised:

* IMAPClientException: the base class for IMAPClient's exceptions and the
* IMAPClientError: the base class for IMAPClient's exceptions and the
most commonly used error.
* IMAPClientAbortError: raised if a serious error has occurred that
means the IMAP connection is no longer usable. The connection should
Expand Down
10 changes: 5 additions & 5 deletions imapclient/exceptions.py
Expand Up @@ -4,34 +4,34 @@
# To ensure backward compatibility, we "rename" the imaplib general
# exception class, so we can catch its exceptions without having to
# deal with it in IMAPClient codebase
IMAPClientException = imaplib.IMAP4.error
IMAPClientError = imaplib.IMAP4.error
IMAPClientAbortError = imaplib.IMAP4.abort
IMAPClientReadOnlyError = imaplib.IMAP4.readonly


class CapabilityError(IMAPClientException):
class CapabilityError(IMAPClientError):
"""
The command tried by the user needs a capability not installed
on the IMAP server
"""


class LoginError(IMAPClientException):
class LoginError(IMAPClientError):
"""
A connection has been established with the server but an error
occurred during the authentication.
"""


class IllegalStateException(IMAPClientException):
class IllegalStateError(IMAPClientError):
"""
The command tried needs a different state to be executed. This
means the user is not logged in or the command needs a folder to
be selected.
"""


class InvalidCriteriaException(IMAPClientException):
class InvalidCriteriaError(IMAPClientError):
"""
A command using a search criteria failed, probably due to a syntax
error in the criteria string.
Expand Down
18 changes: 9 additions & 9 deletions imapclient/imapclient.py
Expand Up @@ -127,7 +127,7 @@ class IMAPClient(object):
# Those exceptions are kept for backward-compatibility, since
# previous versions included these attributes as references to
# imaplib original exceptions
Error = exceptions.IMAPClientException
Error = exceptions.IMAPClientError
AbortError = exceptions.IMAPClientAbortError
ReadOnlyError = exceptions.IMAPClientReadOnlyError

Expand Down Expand Up @@ -250,7 +250,7 @@ def login(self, username, password):
to_unicode(password),
unpack=True,
)
except exceptions.IMAPClientException as e:
except exceptions.IMAPClientError as e:
raise exceptions.LoginError(str(e))

logger.info('Logged in as %s', username)
Expand All @@ -268,7 +268,7 @@ def oauth2_login(self, user, access_token, mech='XOAUTH2', vendor=None):
auth_string += '\1'
try:
return self._command_and_check('authenticate', mech, lambda x: auth_string)
except exceptions.IMAPClientException as e:
except exceptions.IMAPClientError as e:
raise exceptions.LoginError(str(e))

def plain_login(self, identity, password, authorization_identity=None):
Expand All @@ -279,7 +279,7 @@ def plain_login(self, identity, password, authorization_identity=None):
auth_string = '%s\0%s\0%s' % (authorization_identity, identity, password)
try:
return self._command_and_check('authenticate', 'PLAIN', lambda _: auth_string, unpack=True)
except exceptions.IMAPClientException as e:
except exceptions.IMAPClientError as e:
raise exceptions.LoginError(str(e))

def logout(self):
Expand Down Expand Up @@ -316,7 +316,7 @@ def enable(self, *capabilities):
See :rfc:`5161` for more details.
"""
if self._imap.state != 'AUTH':
raise exceptions.IllegalStateException(
raise exceptions.IllegalStateError(
'ENABLE command illegal in state %s' % self._imap.state
)

Expand Down Expand Up @@ -632,7 +632,7 @@ def idle(self):
self._idle_tag = self._imap._command('IDLE')
resp = self._imap._get_response()
if resp is not None:
raise exceptions.IMAPClientException('Unexpected IDLE response: %s' % resp)
raise exceptions.IMAPClientError('Unexpected IDLE response: %s' % resp)

def idle_check(self, timeout=None):
"""Check for any IDLE responses sent by the server.
Expand Down Expand Up @@ -854,7 +854,7 @@ def _search(self, criteria, charset):
# Make BAD IMAP responses easier to understand to the user, with a link to the docs
m = re.match(r'SEARCH command error: BAD \[(.+)\]', str(e))
if m:
raise exceptions.InvalidCriteriaException(
raise exceptions.InvalidCriteriaError(
'{original_msg}\n\n'
'This error may have been caused by a syntax error in the criteria: '
'{criteria}\nPlease refer to the documentation for more information '
Expand Down Expand Up @@ -1202,7 +1202,7 @@ def _check_resp(self, expected, command, typ, data):
Raises IMAPClient.Error if the command fails.
"""
if typ != expected:
raise exceptions.IMAPClientException("%s failed: %s" % (command, to_unicode(data[0])))
raise exceptions.IMAPClientError("%s failed: %s" % (command, to_unicode(data[0])))

def _consume_until_tagged_response(self, tag, command):
tagged_commands = self._imap.tagged_commands
Expand Down Expand Up @@ -1382,7 +1382,7 @@ def _quote(arg):

def _normalise_search_criteria(criteria, charset=None):
if not criteria:
raise exceptions.InvalidCriteriaException('no criteria specified')
raise exceptions.InvalidCriteriaError('no criteria specified')
if not charset:
charset = 'us-ascii'

Expand Down
10 changes: 5 additions & 5 deletions livetest.py
Expand Up @@ -19,7 +19,7 @@
from six import binary_type, text_type, PY3, iteritems

from imapclient.config import parse_config_file, create_client_from_config
from imapclient.exceptions import IMAPClientException
from imapclient.exceptions import IMAPClientError
from imapclient.fixed_offset import FixedOffset
from imapclient.imapclient import IMAPClient, DELETED, RECENT, _dict_bytes_normaliser
from imapclient.response_types import Envelope, Address
Expand Down Expand Up @@ -130,7 +130,7 @@ def clear_test_folders(self):
# delete the currently selected folder.
try:
self.client.close_folder()
except IMAPClientException:
except IMAPClientError:
pass

self.client.folder_encode = False
Expand All @@ -140,7 +140,7 @@ def clear_test_folders(self):
for folder in folder_names:
try:
self.client.delete_folder(folder)
except IMAPClientException:
except IMAPClientError:
if not self.is_fastmail():
raise
self.client.folder_encode = True
Expand Down Expand Up @@ -338,7 +338,7 @@ def test_subscriptions(self):
# Exchange doesn't return an error when subscribing to a
# non-existent folder
if not self.is_exchange():
self.assertRaises(IMAPClientException,
self.assertRaises(IMAPClientError,
self.client.subscribe_folder,
'this folder is not likely to exist')

Expand Down Expand Up @@ -951,7 +951,7 @@ def quiet_logout(client):
"""
try:
client.logout()
except IMAPClientException:
except IMAPClientError:
pass


Expand Down
4 changes: 2 additions & 2 deletions tests/test_enable.py
Expand Up @@ -7,7 +7,7 @@
from mock import Mock

from imapclient import IMAPClient
from imapclient.exceptions import IllegalStateException
from imapclient.exceptions import IllegalStateError
from .imapclient_test import IMAPClientTest


Expand Down Expand Up @@ -65,7 +65,7 @@ def test_wrong_state(self):
self.client._imap.state = 'SELECTED'

self.assertRaises(
IllegalStateException,
IllegalStateError,
self.client.enable,
'FOO',
)
6 changes: 3 additions & 3 deletions tests/test_imapclient.py
Expand Up @@ -12,7 +12,7 @@

import six

from imapclient.exceptions import CapabilityError, IMAPClientException
from imapclient.exceptions import CapabilityError, IMAPClientError
from imapclient.imapclient import IMAPlibLoggerAdapter
from imapclient.fixed_offset import FixedOffset

Expand Down Expand Up @@ -49,11 +49,11 @@ def test_list_sub_folders(self):

def test_list_folders_NO(self):
self.client._imap._simple_command.return_value = ('NO', [b'badness'])
self.assertRaises(IMAPClientException, self.client.list_folders)
self.assertRaises(IMAPClientError, self.client.list_folders)

def test_list_sub_folders_NO(self):
self.client._imap._simple_command.return_value = ('NO', [b'badness'])
self.assertRaises(IMAPClientException, self.client.list_folders)
self.assertRaises(IMAPClientError, self.client.list_folders)

def test_utf7_decoding(self):
self.client._imap._simple_command.return_value = ('OK', [b'something'])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_search.py
Expand Up @@ -8,7 +8,7 @@

import imaplib

from imapclient.exceptions import InvalidCriteriaException
from imapclient.exceptions import InvalidCriteriaError
from imapclient.imapclient import _quoted
from .imapclient_test import IMAPClientTest
from .util import Mock
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_modseq(self):
self.assertEqual(result.modseq, 51101)

def test_nested_empty(self):
self.assertRaises(InvalidCriteriaException, self.client.search, [[]])
self.assertRaises(InvalidCriteriaError, self.client.search, [[]])

def test_single(self):
self.client.search([['FOO']])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_starttls.py
Expand Up @@ -5,7 +5,7 @@
from __future__ import unicode_literals

from imapclient.imapclient import IMAPClient
from imapclient.exceptions import IMAPClientException
from imapclient.exceptions import IMAPClientError

from .imapclient_test import IMAPClientTest
from .util import Mock, patch, sentinel
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_works(self):
def test_command_fails(self):
self.client._imap._simple_command.return_value = "NO", [b'sorry']

with self.assertRaises(IMAPClientException) as raised:
with self.assertRaises(IMAPClientError) as raised:
self.client.starttls(sentinel.ssl_context)
self.assertEqual(str(raised.exception), "starttls failed: sorry")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_util_functions.py
Expand Up @@ -4,7 +4,7 @@

from __future__ import unicode_literals

from imapclient.exceptions import InvalidCriteriaException
from imapclient.exceptions import InvalidCriteriaError
from imapclient.imapclient import (
join_message_ids,
_normalise_search_criteria,
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_no_quoting_when_criteria_given_as_string(self):
self.check('foo bar', None, [b'foo bar'])

def test_None(self):
self.assertRaises(InvalidCriteriaException, _normalise_search_criteria, None, None)
self.assertRaises(InvalidCriteriaError, _normalise_search_criteria, None, None)

def test_empty(self):
self.assertRaises(InvalidCriteriaException, _normalise_search_criteria, '', None)
self.assertRaises(InvalidCriteriaError, _normalise_search_criteria, '', None)

0 comments on commit 8631bb1

Please sign in to comment.