Internal API

Halogen exceptions.

exception halogen.exceptions.ValidationError(errors, attr=None, index=None)[source]

Validation failed.

to_dict()[source]

Return a dictionary representation of the error.

Returns:A dict with the keys: - attr: Attribute which contains the error, or “<root>” if it refers to the schema root. - errors: A list of dictionary representations of the errors.

Halogen basic type validators.

class halogen.validators.GreatThanEqual(value, value_err=None)[source]

Greater than or equal.

validate(value)[source]

Validate the value.

Parameters:value – Value to validate.
Raises:halogen.exception.ValidationError exception when value is invalid.
class halogen.validators.Length(min_length=None, max_length=None, min_err=None, max_err=None)[source]

Length validator that checks the length of a List-like type.

validate(value)[source]

Validate the length of a list.

Parameters:value – List of values.
Raises:halogen.exception.ValidationError exception when length of the list is less than minimum or greater than maximum.
class halogen.validators.LessThanEqual(value, value_err=None)[source]

Less than or equal.

validate(value)[source]

Validate the value.

Parameters:value – Value to validate.
Raises:halogen.exception.ValidationError exception when value is invalid.
class halogen.validators.Range(min=None, max=None, min_err=None, max_err=None)[source]

Range validator.

Validator which succeeds if the value it is passed is greater or equal to min and less than or equal to max. If min is not specified, or is specified as None, no lower bound exists. If max is not specified, or is specified as None, no upper bound exists.

validate(value)[source]

Validate value.

Parameters:value – Value which should be validated.
Raises:halogen.exception.ValidationError exception when either if value less than min in case when

min is not None or if value greater than max in case when max is not None.

class halogen.validators.Validator[source]

Base validator.

classmethod validate(value)[source]

Validate the value.

Parameters:value – Value to validate.
Raises:halogen.exception.ValidationError exception when value is invalid.