def _do_validate(self, name, value): if type(value) is not str: raise InvalidParamsError( extra_msg="Must be string:{0}".format(name)) if not (self.min_length <= len(value) <= self.max_length): raise InvalidParamsError( extra_msg="Length must be in [{0}, {1}]:{2}".format( self.min_length, self.max_length, name)) return value
def _do_validate(self, name, value): if type(value) is not int: raise InvalidParamsError( extra_msg="Must be Integer:{0}".format(name)) if not (self.minimum <= value <= self.maximum): raise InvalidParamsError( extra_msg="Must be in [{0}, {1}]:{2}".format( self.minimum, self.maximum, name)) return value
def _do_validate(self, name, value): if type(value) is not list: raise InvalidParamsError(extra_msg="Must be list:{0}".format(name)) if not (self.min_length <= len(value) <= self.max_length): raise InvalidParamsError( extra_msg="List length must be in [{0}, {1}]:{2}".format( self.min_length, self.max_length, name)) result = [] for i, v in enumerate(value): v = self.list_definition.validate(name="v", params={"v": v})["v"] result.append(v) return result
def _do_validate(self, name, value): if type(value) is not str: raise InvalidParamsError( extra_msg="Must be string:{0}".format(name)) if not (self.min_length <= len(value) <= self.max_length): raise InvalidParamsError( extra_msg="Length must be in [{0}, {1}]:{2}".format( self.min_length, self.max_length, name)) if not re.match( r'(https?)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]', value): raise InvalidParamsError(extra_msg="Not a url:{0}".format(name)) return value
def _do_validate(self, name, value): try: value_dt = datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S') if self.to_datetime: return value_dt else: return value except ValueError: raise InvalidParamsError( extra_msg="Datetime format error:{0}".format(name))
def _do_validate(self, name, value): if value not in self.enums: raise InvalidParamsError(extra_msg="value not in [{0}]:{1}".format( ", ".join(list(map(lambda x: str(x), self.enums))), name)) return value
def _do_validate(self, name, value): if not isinstance(value, (str, int)): raise InvalidParamsError( extra_msg="Must be integer or string:{0}".format(name)) return value