def _validate_max(self, max_value, field, value): """{'nullable': False }""" try: if isarray(value) and any(v > max_value for v in value): self._error(field, errors.MAX_VALUE) elif self.__validate_type_range(value): start, stop, step = value["start"], value["stop"], value.get( "step", 1) if (stop - 1 > max_value) if step > 0 else (start > max_value): self._error(field, errors.MAX_VALUE) elif value > max_value: self._error(field, errors.MAX_VALUE) except TypeError: pass
def __validate_type_list_or_single(self, x, test_fn): if test_fn(x): return True elif isarray(x): return all(map(test_fn, x)) return False
def _normalize_coerce_aslist(self, x, type_=None): if not isarray(x): x = [x] if type_: x = list(map(type_, x)) return x
def __validate_enums(self, x, enum): values = enum_values(enum) if isarray(x): return contains(values, *x) return x in values