Validators¶
-
class
lira.validators.Validator(data=None)¶ Base class for validators.
The
run()method should be called to validate the given data. Usage:validator = Validator(data="Validate me!") validator.run() print(validator.is_valid) print(validator.data) print(validator.message)
-
is_valid¶ Was the data valid?
-
error: Exception¶ Current raised exception.
-
message¶ Optional message to show after the validation.
-
data¶ Data to validate.
-
tries¶ Current number of tries.
-
previous_errors¶ List of previous validation errors.
-
run()¶ Run the validator.
This will increment
tries, and in case of failure it wil add the exception toprevious_errors.
-
on_success()¶ To be called if the validation was successful.
-
on_failure(e: lira.validators.ValidationError)¶ To be called if the validation wasn’t successful.
-
on_exception(e: Exception)¶ To be called if an unhandled exception was raised.
-
validate(data: str) → bool¶ Validate the value.
- Raises
ValidationError – If the value is incorrect.
- Returns
The final value of
data.
-
-
class
lira.validators.TestBlockValidator(node)¶ Base validator for
lira.parsers.nodes.TestBlocknodes.- Parameters
node (lira.parsers.nodes.TestBlock) – TestBlock node to validate.
-
class
lira.validators.ValidationError¶ Exception to raise when the data isn’t valid.