Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/fastjsonschema/exceptions.py: 80%
20 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1import re
4SPLIT_RE = re.compile(r'[\.\[\]]+')
7class JsonSchemaException(ValueError):
8 """
9 Base exception of ``fastjsonschema`` library.
10 """
13class JsonSchemaValueException(JsonSchemaException):
14 """
15 Exception raised by validation function. Available properties:
17 * ``message`` containing human-readable information what is wrong (e.g. ``data.property[index] must be smaller than or equal to 42``),
18 * invalid ``value`` (e.g. ``60``),
19 * ``name`` of a path in the data structure (e.g. ``data.property[index]``),
20 * ``path`` as an array in the data structure (e.g. ``['data', 'property', 'index']``),
21 * the whole ``definition`` which the ``value`` has to fulfil (e.g. ``{'type': 'number', 'maximum': 42}``),
22 * ``rule`` which the ``value`` is breaking (e.g. ``maximum``)
23 * and ``rule_definition`` (e.g. ``42``).
25 .. versionchanged:: 2.14.0
26 Added all extra properties.
27 """
29 def __init__(self, message, value=None, name=None, definition=None, rule=None):
30 super().__init__(message)
31 self.message = message
32 self.value = value
33 self.name = name
34 self.definition = definition
35 self.rule = rule
37 @property
38 def path(self):
39 return [item for item in SPLIT_RE.split(self.name) if item != '']
41 @property
42 def rule_definition(self):
43 if not self.rule or not self.definition:
44 return None
45 return self.definition.get(self.rule)
48class JsonSchemaDefinitionException(JsonSchemaException):
49 """
50 Exception raised by generator of validation function.
51 """