示例#1
0
 def validate(self, data: object) -> object:
     from datetime import datetime
     try:
         cleaned_data = datetime.strptime(data, '%Y-%m-%d').date()
         return cleaned_data
     except (ValueError, TypeError):
         raise SchemaError(self.message)
示例#2
0
 def validate(
     self,
     data: object,
     watch_for_exceptions: Exception = (ValueError, TypeError)
 ) -> object:
     try:
         return self.pipe(data)
     except watch_for_exceptions as e:
         message = str(e)
         raise SchemaError(self.message or message)
示例#3
0
    def validate(self, data: object) -> object:
        messages = []

        for condition in self.conditions:
            try:
                return condition.validate(data)
            except SchemaError as err:
                messages.append(err.error)

        message = self.message.format(messages=", ".join(messages))
        raise SchemaError(message)
示例#4
0
 def validate(self, data: object) -> object:
     if not self._check(data):
         raise SchemaError(self.message.format(maxValue=self.maxValue))
     return data
示例#5
0
 def validate(self, data: object) -> object:
     if not self._check(data):
         raise SchemaError(self.message)
     return data
示例#6
0
 def validate(self, data: object) -> object:
     if not self.predicate(data):
         raise SchemaError(self.get_message(data))
     return data