def from_native(self, value): if value in validators.EMPTY_VALUES: return None if isinstance(value, datetime.time): return value for format in self.input_formats: if format.lower() == ISO_8601: try: parsed = parse_time(value) except (ValueError, TypeError): pass else: if parsed is not None: return parsed else: try: parsed = datetime.datetime.strptime(value, format) except (ValueError, TypeError): pass else: return parsed.time() msg = self.error_messages['invalid'] % readable_time_formats( self.input_formats) raise ValidationError(msg)
def from_native(self, value): if value in validators.EMPTY_VALUES: return None if isinstance(value, datetime.time): return value for format in self.input_formats: if format.lower() == ISO_8601: try: parsed = parse_time(value) except (ValueError, TypeError): pass else: if parsed is not None: return parsed else: try: parsed = datetime.datetime.strptime(value, format) except (ValueError, TypeError): pass else: return parsed.time() msg = self.error_messages['invalid'] % readable_time_formats(self.input_formats) raise ValidationError(msg)
def from_native(self, value): if value in validators.EMPTY_VALUES: return None if isinstance(value, datetime.time): return value try: parsed = parse_time(value) assert parsed is not None return parsed except (ValueError, TypeError): msg = self.error_messages['invalid'] % value raise ValidationError(msg)
def from_native(self, value): if value in validators.EMPTY_VALUES: return None if isinstance(value, datetime.time): return value try: parsed = parse_time(value) assert parsed is not None return parsed except ValueError: msg = self.error_messages['invalid'] % value raise ValidationError(msg)