示例#1
0
 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)
示例#2
0
文件: cache.py 项目: jamesevers/faust
 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
示例#3
0
文件: cache.py 项目: jamesevers/faust
 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),
         )
示例#4
0
文件: cache.py 项目: bralicea/Trades
 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,
         )