Permalink
Browse files

Merge pull request #297 from mlorant/fix-294-exceptions-names

Harmonize exceptions names with Error suffix
  • Loading branch information...
NicolasLM committed Oct 5, 2017
2 parents e521020 + 8631bb1 commit 6cc77d74fc4895f17e116432d75d010c6e6c7353
View
@@ -25,7 +25,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
View
@@ -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.
View
@@ -150,7 +150,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
@@ -277,7 +277,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)
@@ -295,7 +295,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):
@@ -306,7 +306,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):
@@ -343,7 +343,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
)
@@ -659,7 +659,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.
@@ -881,7 +881,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 '
@@ -1229,7 +1229,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
@@ -1409,7 +1409,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'
View
@@ -20,7 +20,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, SocketTimeout
@@ -133,7 +133,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
@@ -143,7 +143,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
@@ -341,7 +341,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')
@@ -986,7 +986,7 @@ def quiet_logout(client):
"""
try:
client.logout()
except IMAPClientException:
except IMAPClientError:
pass
View
@@ -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
@@ -65,7 +65,7 @@ def test_wrong_state(self):
self.client._imap.state = 'SELECTED'
self.assertRaises(
IllegalStateException,
IllegalStateError,
self.client.enable,
'FOO',
)
View
@@ -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
@@ -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'])
View
@@ -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
@@ -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']])
View
@@ -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
@@ -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")
@@ -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,
@@ -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 6cc77d7

Please sign in to comment.