Module validator
Set of validating objects
Suitable to be the validating functions of editor.property objects
- Imports:
- re
- Classes:
- IntValidator(Validator): Conversion and validation of integers
- StringValidator(Validator): Conversion and validation of string
- Validator(object): Base class for the validation objects
- Attributes:
- to_int = IntValidator
- to_string = StringValidator
Class validator.IntValidator
- Bases:
- Validator
Conversion and validation of integers
- Methods:
- __init__(self, v, *args, **kw): Initialisation
- greater_or_equal_than(self, min, msg='Must be greater or equal than %(min)d'): Check that the value is greater or equal than a limit
- greater_than(self, min, msg='Must be greater than %(min)d'): Check that the value is greater than a limit
- lesser_or_equal_than(self, max, msg='Must be lesser or equal than %(max)d'): Check that the value is lesser or equal than a limit
- lesser_than(self, max, msg='Must be lesser than %(max)d'): Check that the value is lesser than a limit
- to_int(self): Return the value, converted to an integer
- Attributes:
- __call__ = to_int
Method validator.IntValidator.__init__
Back to validator.IntValidator
- Arguments:
- self, v, *args, **kw
Initialisation
Check that the value is an integer
- In:
- v -- value to validate
Method validator.IntValidator.greater_or_equal_than
Back to validator.IntValidator
- Arguments:
- self, min, msg='Must be greater or equal than %(min)d'
Check that the value is greater or equal than a limit
- In:
- max -- the limit
- msg -- message to raise
- Return:
- self
Method validator.IntValidator.greater_than
Back to validator.IntValidator
- Arguments:
- self, min, msg='Must be greater than %(min)d'
Check that the value is greater than a limit
- In:
- max -- the limit
- msg -- message to raise
- Return:
- self
Method validator.IntValidator.lesser_or_equal_than
Back to validator.IntValidator
- Arguments:
- self, max, msg='Must be lesser or equal than %(max)d'
Check that the value is lesser or equal than a limit
- In:
- max -- the limit
- msg -- message to raise
- Return:
- self
Method validator.IntValidator.lesser_than
Back to validator.IntValidator
- Arguments:
- self, max, msg='Must be lesser than %(max)d'
Check that the value is lesser than a limit
- In:
- max -- the limit
- msg -- message to raise
- Return:
- self
Method validator.IntValidator.to_int
Back to validator.IntValidator
- Arguments:
- self
Return the value, converted to an integer
- Return:
- the integer value
Class validator.StringValidator
- Bases:
- Validator
Conversion and validation of string
- Methods:
- isalnum(self, msg='some characters are not alphanumeric'):
- isalpha(self, msg='some characters are not alphabetic'):
- isdigit(self, msg='some characters are not digits'):
- islower(self, msg='some characters are not lowercase'):
- isspace(self, msg='some characters are not whitespace'):
- isupper(self, msg='some characters are not uppercase'):
- length_equal(self, v, msg='Length must be %(len)d characters'): Check that the value has an exact length
- longer_or_equal_than(self, min, msg='Length must be longer or equal than %(min)d characters'): Check that the value is longer or equal than a limit
- longer_than(self, min, msg='Length must be longer than %(min)d characters'): Check that the value is longer than a limit
- match(self, r, msg='Incorrect format'): Check that the value respects a format given as a regexp
- not_empty(self, msg="Can't be empty"): Check that the value is not empty
- shorter_or_equal_than(self, max, msg='Length must be shorter or equal than %(max)d characters'): Check that the value is shorter or equal than a limit
- shorter_than(self, max, msg='Length must be shorter than %(max)d characters'): Check that the value is shorter than a limit
- to_int(self, base=10): Return the value, converted to an integer
- to_string(self): Return the value, converted to a string
- Attributes:
- __call__ = to_string
Method validator.StringValidator.length_equal
Back to validator.StringValidator
- Arguments:
- self, v, msg='Length must be %(len)d characters'
Check that the value has an exact length
- In:
- v -- the length
- msg -- message to raise
- Return:
- self
Method validator.StringValidator.longer_or_equal_than
Back to validator.StringValidator
- Arguments:
- self, min, msg='Length must be longer or equal than %(min)d characters'
Check that the value is longer or equal than a limit
- In:
- min -- the limit
- msg -- message to raise
- Return:
- self
Method validator.StringValidator.longer_than
Back to validator.StringValidator
- Arguments:
- self, min, msg='Length must be longer than %(min)d characters'
Check that the value is longer than a limit
- In:
- min -- the limit
- msg -- message to raise
- Return:
- self
Method validator.StringValidator.match
Back to validator.StringValidator
- Arguments:
- self, r, msg='Incorrect format'
Check that the value respects a format given as a regexp
- In:
- r -- the regexp
- msg -- message to raise
- Return:
- self
Method validator.StringValidator.not_empty
Back to validator.StringValidator
- Arguments:
- self, msg="Can't be empty"
Check that the value is not empty
- In:
- msg -- message to raise
- Return:
- self
Method validator.StringValidator.shorter_or_equal_than
Back to validator.StringValidator
- Arguments:
- self, max, msg='Length must be shorter or equal than %(max)d characters'
Check that the value is shorter or equal than a limit
- In:
- max -- the limit
- msg -- message to raise
- Return:
- self
Method validator.StringValidator.shorter_than
Back to validator.StringValidator
- Arguments:
- self, max, msg='Length must be shorter than %(max)d characters'
Check that the value is shorter than a limit
- In:
- max -- the limit
- msg -- message to raise
- Return:
- self
Method validator.StringValidator.to_int
Back to validator.StringValidator
- Arguments:
- self, base=10
Return the value, converted to an integer
- In:
- base -- base for the conversion
- Return:
- the integer value
Method validator.StringValidator.to_string
Back to validator.StringValidator
- Arguments:
- self
Return the value, converted to a string
- Return:
- the string value
Class validator.Validator
- Bases:
- object
Base class for the validation objects
- Methods:
- __init__(self, v, strip=False, rstrip=False, lstrip=False, chars=None): Initialization
Method validator.Validator.__init__
- Arguments:
- self, v, strip=False, rstrip=False, lstrip=False, chars=None
Initialization
This object only do conversions, possibly removing characters at the beginning / end of the value
- In:
- v -- value to validate
- strip -- remove the characters at the beginning and the end
- rstrip -- remove the characters at the end
- lstrip -- remove the characters at the beginning
- chars -- list of characters to removed, spaces by default