From a30d3215282d7a939a3fc617a55f6fcdc005a33d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 18:21:56 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/middleware/csrf.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fastapi/middleware/csrf.py b/fastapi/middleware/csrf.py index 515b5e7377..8399f2e146 100644 --- a/fastapi/middleware/csrf.py +++ b/fastapi/middleware/csrf.py @@ -2,7 +2,8 @@ import functools import http.cookies import secrets from re import Pattern -from typing import Dict, List, Optional, Set, Any, cast, Callable, Coroutine +from typing import Any, Callable, Coroutine, Dict, List, Optional, Set, cast + from itsdangerous import BadSignature from itsdangerous.url_safe import URLSafeSerializer from starlette.datastructures import URL, MutableHeaders @@ -136,7 +137,7 @@ class CSRFMiddleware: return cast(str, csrf_token) def _generate_csrf_token(self) -> str: - token = self.serializer.dumps(secrets.token_urlsafe(128)) + token = self.serializer.dumps(secrets.token_urlsafe(128)) return cast(str, token) def _csrf_tokens_match(self, token1: str, token2: str) -> bool: @@ -152,9 +153,12 @@ class CSRFMiddleware: content="CSRF token verification failed", status_code=403 ) - def _receive_with_body(self, receive: Any, body: bytes) -> Callable[[], Coroutine[Any, Any, Dict[str, Any]]]: - async def inner() -> dict : + def _receive_with_body( + self, receive: Any, body: bytes + ) -> Callable[[], Coroutine[Any, Any, Dict[str, Any]]]: + async def inner() -> dict: return {"type": "http.request", "body": body, "more_body": False} + return inner @@ -170,4 +174,5 @@ def csrf_token_processor(csrf_cookie_name: str, csrf_header_name: str): "csrf_input": csrf_input, "csrf_header": csrf_header, } - return processor \ No newline at end of file + + return processor