1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
from logging import getLogger |
3
|
|
|
|
4
|
|
|
log = getLogger(__name__) |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
def Raise(exception): # NOQA |
8
|
|
|
raise exception |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class AuxlibError(object): |
12
|
|
|
"""Mixin to identify exceptions associated with the auxlib package.""" |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class AuthenticationError(AuxlibError, ValueError): |
16
|
|
|
pass |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class NotFoundError(AuxlibError, KeyError): |
20
|
|
|
pass |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class InitializationError(AuxlibError, EnvironmentError): |
24
|
|
|
pass |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class SenderError(AuxlibError, IOError): |
28
|
|
|
pass |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
class AssignmentError(AuxlibError, AttributeError): |
32
|
|
|
pass |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class ValidationError(AuxlibError, TypeError): |
36
|
|
|
|
37
|
|
|
def __init__(self, key, value=None, valid_types=None, msg=None): |
38
|
|
|
self.__cause__ = None # in python3 don't chain ValidationError exceptions |
39
|
|
|
if msg is not None: |
40
|
|
|
super(ValidationError, self).__init__(msg) |
41
|
|
|
elif value is None: |
42
|
|
|
super(ValidationError, self).__init__("Value for {0} cannot be None." |
43
|
|
|
"".format(key)) |
44
|
|
|
elif valid_types is None: |
45
|
|
|
super(ValidationError, self).__init__("Invalid value {0} for {1}" |
46
|
|
|
"".format(value, key)) |
47
|
|
|
else: |
48
|
|
|
super(ValidationError, self).__init__("{0} must be of type {1}, not {2}" |
49
|
|
|
"".format(key, valid_types, repr(value))) |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
class ThisShouldNeverHappenError(AuxlibError, AttributeError): |
53
|
|
|
pass |
54
|
|
|
|