| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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) |