arganic.validators
Dir
Bases: Validator
Directory Validator.
validate
Test the existence of a directory according to the path provided.
Parameters:
-
value
–Path to the directory that must exist on the file system.
Returns:
-
bool
–True if the directory exists.
Raises:
-
FileNotFoundError
–If the directory does not exist on the file system.
Examples:
Email
Bases: Validator
Email address Validator.
validate
Validates the syntax of an email address.
Parameters:
-
value
–Email address whose syntax must be checked.
Returns:
-
bool
–If the value provided is a correct email address format.
Raises:
-
ValueError
–If the value provided is not a valid email address.
Examples:
File
Bases: Validator
File Validator
validate
Test the existence of a file according to the path provided.
Parameters:
-
value
–Path to the file that must exist on the file system.
Returns:
-
bool
–True if the file exists.
Raises:
-
FileNotFoundError
–If the file does not exist on the file system.
Examples:
MaxLength
Bases: Validator
Maximum length validator.
__init__
Max length Validator constructor.
Parameters:
-
max_length
(int
) –The maximum length that the values to validate must not exceed.
validate
Validates a value whose maximum length must not be greater than the value specified in the validator constructor.
The value must be of a type supporting the builtin len() Python function.
Parameters:
-
value
–The value to validate.
Returns:
-
bool
–True if the validation succeeded.
Raises:
-
TypeError
–If the length of the value is longer than the specified maximum length.
Examples:
MinLength
Bases: Validator
Minimum length validator.
__init__
Max length Validator constructor.
Parameters:
-
min_length
(int
) –The minimum length that the value must be.
validate
Verifies that the provided value have a length must be at least the minimum value given in the validator constructor.
The value must be of a type supporting the builtin len() Python function.
Parameters:
-
value
–The value to validate.
Returns:
-
bool
–True if the validation succeeded.
Raises:
-
TypeError
–If the length of the value is shorter than the specified minimum length.
Examples:
Url
Bases: Validator
URL Validator.
validate
Validate if an URL is well formatted. supported protocols: http, https, ftp, ftps.
Parameters:
-
value
–The value of the URL to validate.
Returns:
-
bool
–True if the URL is well formatted.
Raises:
-
ValueError
–If the provided value is an invalid Url.
Examples:
Validator
Bases: ABC
Base class for validators.
It's possible to define your own validators by extending this class.
Examples:
Example of a custom validator.