コード例 #1
0
 def validate_or_error(
     cls: typing.Type["Schema"], value: typing.Any, *, strict: bool = False
 ) -> ValidationResult:
     try:
         value = cls.validate(value, strict=strict)
     except ValidationError as error:
         return ValidationResult(value=None, error=error)
     return ValidationResult(value=value, error=None)
コード例 #2
0
ファイル: fields.py プロジェクト: jordic/typesystem
 def validate_or_error(self,
                       value: typing.Any,
                       *,
                       strict: bool = False) -> ValidationResult:
     try:
         value = self.validate(value, strict=strict)
     except ValidationError as error:
         return ValidationResult(value=None, error=error)
     return ValidationResult(value=value, error=None)
コード例 #3
0
ファイル: __init__.py プロジェクト: amenson1983/2-week
    async def validate(self, request: Request) -> ValidationResult:
        data = None  # type: Optional[dict]
        content_type = request.headers.get("Content-Type")
        if content_type == "application/x-www-form-urlencoded":
            form = await request.form()
            data = dict(form)
        elif content_type == "application/json":
            data = await request.json()
        else:
            return ValidationResult(
                value=None,
                error=ValidationError(messages=[
                    Message(
                        text="Invalid Content-Type value.",
                        code="invalid",
                        index=["content_type"],
                    )
                ]),
            )

        return self.schema.validate_or_error(data)
コード例 #4
0
 def __init__(self):
     self.elements = {}
     self.uuid = uuid.uuid4()
     self.validation_result = ValidationResult()
     self.widgets = {}
     self.stylesheets = {}