def validate(self): """ Perform validation of this edge raising a ValidationError if any problems are encountered. """ if self._id is None: if self._inV is None: raise ValidationError( 'in vertex must be set before saving new edges') if self._outV is None: raise ValidationError( 'out vertex must be set before saving new edges') super(Edge, self).validate()
def __call__(self, value): try: super(EmailValidator, self).__call__(value) except ValidationError as e: # Trivial case failed. Try for possible IDN domain-part if value and isinstance(value, string_types) and '@' in value: parts = value.split('@') try: parts[-1] = parts[-1].encode('idna').decode('ascii') except UnicodeError: raise ValidationError(self.message.format(value), code=self.code) super(EmailValidator, self).__call__('@'.join(parts)) else: raise ValidationError(self.message.format(value), code=self.code) return value
def __call__(self, value): """ Validates that the input matches the regular expression. """ if not self.regex.search(text_type(value)): raise ValidationError(self.message, code=self.code) else: return value
def __call__(self, value): try: super(URLValidator, self).__call__(value) except ValidationError as e: # Trivial case failed. Try for possible IDN domain if value: value = text_type(value) scheme, netloc, path, query, fragment = urlsplit(value) try: # IDN -> ACE netloc = netloc.encode('idna').decode('ascii') except UnicodeError: # invalid domain part raise ValidationError(self.message.format(value), code=self.code) url = urlunsplit((scheme, netloc, path, query, fragment)) return super(URLValidator, self).__call__(url) else: raise ValidationError(self.message.format(value), code=self.code) return value
def __call__(self, value): super(DateTimeUTCValidator, self).__call__(value) if value is None: return if not isinstance(value, datetime.datetime) and value is not None: raise ValidationError(self.message.format(value), code=self.code) if value and value.tzinfo != utc: # print_("Got value with timezone: {} - {}".format(value, value.tzinfo)) try: value = value.astimezone(tz=utc) except ValueError: # last ditch effort try: value = value.replace(tzinfo=utc) except (AttributeError, TypeError): raise ValidationError( self.message.format(value), code=self.code) except AttributeError: # pragma: no cover # This should never happen, unless it isn't a datetime object raise ValidationError(self.message % (value, ), code=self.code) # print_("Datetime passed validation: {} - {}".format(value, value.tzinfo)) return value
def validate(self, value): """ Returns a cleaned and validated value. Raises a ValidationError if there's a problem :rtype: Object """ if self.choices: orig_value = value value = GraphProperty.get_value_from_choices(value, self.choices) if value is None: raise ValidationError( '{} - Value `{}` is not in available choices'.format( self.db_field_name, orig_value)) if value is None: if self.has_default: return self.validator(self.get_default()) elif self.required: raise ValidationError( '{} - None values are not allowed'.format( self.db_field_name)) else: return None return self.validator(value)
def __call__(self, value): super(PositiveIntegerValidator, self).__call__(value) if value < 0: raise ValidationError("Value must be 0 or greater") return value
def __call__(self, value): if not isinstance(value, self.__class__.data_types): raise ValidationError(self.message, code=self.code) return value
def __call__(self, value): if not isinstance(value, bool_types): raise ValidationError(self.message, self.code) return value
def __call__(self, value): if not isinstance(value, datetime.datetime) and value is not None: raise ValidationError(self.message.format(value), code=self.code) return value
def __call__(self, value): if not isinstance(value, dict): raise ValidationError(self.message, code=self.code) return value
def __call__(self, value): if not isinstance(value, self.data_type): raise ValidationError(self.message.format(value), code=self.code) return value