def validate(self, value): if value is None: return None if not isinstance(value, list): raise exception.InvalidValue(value=value, type=self.type_name) try: return [self.type.validate(v) for v in value] except Exception: LOG.exception(_LE('Failed to validate received value')) raise exception.InvalidValue(value=value, type=self.type_name)
def validate(cls, value, min_length=0, max_length=None): if value is None: return None try: strutils.check_string_length(value, min_length=min_length, max_length=max_length) except TypeError: raise exception.InvalidValue(value=value, type=cls.type_name) except ValueError as e: raise exception.InvalidValue(message=str(e)) return value
def validate(cls, value): if value is None: return None if not isinstance(value, six.string_types): raise exception.InvalidValue(value=value, type=cls.type_name) return value
def validate(cls, value, minimum=None): if value is None: return None if not isinstance(value, six.integer_types): try: value = int(value) except Exception: LOG.exception(_LE('Failed to convert value to int')) raise exception.InvalidValue(value=value, type=cls.type_name) if minimum is not None and value < minimum: message = _("Integer '%(value)s' is smaller than " "'%(min)d'.") % { 'value': value, 'min': minimum } raise exception.InvalidValue(message=message) return value
def validate(cls, value, default=None): if value is None: value = default if not isinstance(value, bool): try: value = strutils.bool_from_string(value, strict=True) except Exception: LOG.exception(_LE('Failed to convert value to bool')) raise exception.InvalidValue(value=value, type=cls.type_name) return value
def validate(self, value): if value is None: return None if not isinstance(value, self.user_class): try: value = self.user_class(**value) except Exception: LOG.exception(_LE('Failed to validate received value')) raise exception.InvalidValue(value=value, type=self.type_name) return value