async def _inner(view: View, request: Request, *args: Any, **kwargs: Any) -> Response: try: data: dict = await request.json() validated_object: model = model.parse_obj(data) except ValidationError as e: if include_schema: return view.json(value={ 'errors': e.errors(), 'schema': model.schema() }, status=422) return view.json(value={'errors': e.errors()}) return await fun(view, request, validated_object, *args, **kwargs)
async def get_view(self, key: str, view: View) -> Optional[Response]: backend = self._view_backend(view) with suppress(backend.Unavailable): payload = await backend.get(key) if payload is not None: return view.bytes_to_response(payload) return None
async def set_view(self, key: str, view: View, response: Response, timeout: Seconds) -> None: backend = self._view_backend(view) with suppress(backend.Unavailable): return await backend.set( key, view.response_to_bytes(response), want_seconds(timeout if timeout is not None else self.timeout), )
async def set_view(self, key: str, view: View, response: Response, timeout: Seconds = None) -> None: """Set cached value for HTTP view request.""" backend = self._view_backend(view) _timeout = timeout if timeout is not None else self.timeout with suppress(backend.Unavailable): return await backend.set( key, view.response_to_bytes(response), want_seconds(_timeout) if _timeout is not None else None, )