-
Notifications
You must be signed in to change notification settings - Fork 1
/
transforms.py
65 lines (46 loc) · 1.99 KB
/
transforms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class ArgumentNotProvidedError(Exception):
"""Raised when a transform is called without a mandatory argument"""
def __init__(self, argument):
super().__init__("Must provide a value for argument: {}".format(argument))
class InvalidArgumentError(Exception):
"""Raised when a transform is called with an invalid argument"""
def __init__(self, message):
super().__init__(message)
class ValidatorError(Exception):
def __init__(self, desc):
self.desc = desc
def get_description(self):
return self.desc
class InvalidMethodError(Exception):
"""Raised when a transform is called with an invalid method"""
def __init__(self, args):
super().__init__(
"Invalid Method. Available methods: {}".format(
", ".join(str(arg) for arg in args)
)
)
class UnsupportedArgumentError(Exception):
"""Raised when a transform is created with an unsupported argument"""
def __init__(self, transform, method=None):
if method is None:
name = 'transform "{}"'.format(transform.__class__.__name__)
else:
name = 'method "{}"'.format(method)
msg = "Invalid arguments for {}. ".format(name)
if transform.arguments:
msg += "Allowed arguments: {}".format(", ".join(transform.arguments))
else:
msg += "{} takes no arguments.".format(name.title())
super().__init__(msg)
class MissingArgumentError(Exception):
"""Raised when an transform is executed while missing a mandatory argument"""
def __init__(self, arg, index=None):
if index is None:
msg = "Transform "
else:
msg = "Transform at index {} ".format(index)
super().__init__(msg + "missing mandatory argument: {}".format(arg))
class InvalidSelectionError(Exception):
"""Raised when an invalid selection is made in a selector"""
def __init__(self, msg):
super().__init__("Invalid selection. {}".format(msg))