Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validate(self, value):
- """Assert that provided value is compatible with this property.
- Args:
- value: Value to validate against this Property.
- Returns:
- A valid value, either the input unchanged or adapted to the
- required type.
- Raises:
- BadValueError if the value is not appropriate for this
- property in any way.
- """
- if self.empty(value):
- if self.required:
- raise BadValueError('Property %s is required' % self.name)
- else:
- if self.choices:
- if value not in self.choices:
- raise BadValueError('Property %s is %r; must be one of %r' %
- (self.name, value, self.choices))
- if self.validator is not None:
- self.validator(value)
- return value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement