Debian Codegraph @

metomi/isodatetime/exceptions.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # ----------------------------------------------------------------------------
3 # Copyright (C) British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # ----------------------------------------------------------------------------
18
19
20 class IsodatetimeError(Exception):
21 """Generic exception for Isodatetime errors.
22
23 This exception is raised in-place of "expected" errors where a short
24 message to the user is more appropriate than traceback.
25
26
27 """
28
29
30 class BadInputError(IsodatetimeError, ValueError):
31
32 """An error raised when constructor inputs are invalid."""
33
34 CONFLICT = "Conflicting input: {0} but have {1}"
35 INT_CAST = "Invalid input for {0}: {1}: {2}"
36 INT_REMAINDER = "Non-integer like number for {0}: {1}"
37 MISSING = "Missing input: {0} needs {1}"
38 OUT_OF_BOUNDS = "Invalid input (out of bounds): {0}: {1}"
39 RECURRENCE = "Invalid recurrence info: {0}"
40 TYPE = "Invalid type for {0}: {1}{2}"
41 VALUES = "Invalid input for {0}: {1}: allowed: {2}"
42
43 def __str__(self):
44 format_string = self.args[0]
45 format_args = self.args[1:]
46 return format_string.format(*format_args)
47
48
49 class OffsetValueError(IsodatetimeError, ValueError):
50
51 """Bad offset value."""
52
53 def __str__(self):
54 return "%s: bad offset value" % self.args[0]
55
56
57 class TimePointDumperBoundsError(IsodatetimeError, ValueError):
58
59 """An error raised when a TimePoint can't be dumped within bounds."""
60
61 MESSAGE = "Cannot dump TimePoint {0}: {1} not in bounds {2} to {3}."
62
63 def __str__(self):
64 return self.MESSAGE.format(*self.args)
65
66
67 class StrftimeSyntaxError(IsodatetimeError, ValueError):
68
69 """An error denoting invalid or unsupported strftime/strptime syntax."""
70
71 BAD_STRFTIME_INPUT = "Invalid strftime/strptime representation: {0}"
72
73 def __str__(self):
74 return self.BAD_STRFTIME_INPUT.format(*self.args)
75
76
77 class ISO8601SyntaxError(IsodatetimeError, ValueError):
78
79 """An error denoting invalid input syntax."""
80
81 BAD_TIME_INPUT = "Invalid ISO 8601 {0} representation: {1}"
82
83 def __str__(self):
84 return self.BAD_TIME_INPUT.format(*self.args)
85
86
87 class StrptimeConversionError(IsodatetimeError, ValueError):
88
89 """An error denoting bad conversion from a strftime/strptime format."""
90
91 BAD_CONVERSION = "Bad conversion for strftime/strptime input '{0}': '{1}'"
92
93 def __str__(self):
94 return self.BAD_CONVERSION.format(*self.args)