validation.py 604 B

1234567891011121314151617181920
  1. import re
  2. from darabonba.exceptions import ValidateException
  3. def assert_integer_positive(integer, name):
  4. if isinstance(integer, int) and integer > 0:
  5. return
  6. raise ValidateException("{0} should be a positive integer.".format(name))
  7. def validate_pattern(prop, prop_name, pattern):
  8. match_obj = re.search(pattern, prop, re.M | re.I)
  9. if not match_obj:
  10. raise ValidateException('The parameter %s not match with %s' % (prop_name, pattern))
  11. def is_null(value, name):
  12. if value is None:
  13. raise ValidateException("The parameter {0} should not be null.".format(name))