Advertisement
Guest User

AppEngine DB Property validate

a guest
Oct 2nd, 2013
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def validate(self, value):
  2.     """Assert that provided value is compatible with this property.
  3.  
  4.    Args:
  5.      value: Value to validate against this Property.
  6.  
  7.    Returns:
  8.      A valid value, either the input unchanged or adapted to the
  9.      required type.
  10.  
  11.    Raises:
  12.      BadValueError if the value is not appropriate for this
  13.      property in any way.
  14.    """
  15.     if self.empty(value):
  16.       if self.required:
  17.         raise BadValueError('Property %s is required' % self.name)
  18.     else:
  19.       if self.choices:
  20.         if value not in self.choices:
  21.           raise BadValueError('Property %s is %r; must be one of %r' %
  22.                               (self.name, value, self.choices))
  23.     if self.validator is not None:
  24.       self.validator(value)
  25.     return value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement