Skip to content

Commit 15880f6

Browse files
committed
feat: wrap compiled implementations with uncompiled
1 parent bdc96be commit 15880f6

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ mypy-args = [
7171
'--disallow-incomplete-defs',
7272
'--strict',
7373
]
74-
only-include = [ '/src' ]
74+
only-include = [
75+
'/src/fastapi_csrf_protect/core.py',
76+
'/src/fastapi_csrf_protect/csrf_config.py',
77+
'/src/fastapi_csrf_protect/exceptions.py',
78+
'/src/fastapi_csrf_protect/load_config.py',
79+
]
7580

7681

7782
[tool.hatch.build.targets.wheel.hooks.mypyc.options]

src/fastapi_csrf_protect/__init__.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,47 @@
1313
"""
1414

1515
### Standard packages ###
16-
from typing import Tuple
16+
from typing import Any, Callable, ClassVar, Optional, Sequence, Tuple
17+
18+
### Third-party packages ###
19+
from starlette.datastructures import Headers
20+
from starlette.requests import Request
21+
from starlette.responses import Response
1722

1823
### Local modules ###
19-
from fastapi_csrf_protect.core import CsrfProtect
24+
from fastapi_csrf_protect.core import CsrfProtect as CsrfProtectImpl
25+
26+
class CsrfProtect:
27+
impl: ClassVar[CsrfProtectImpl] = CsrfProtectImpl()
28+
29+
@classmethod
30+
def load_config(cls, settings: Callable[..., Sequence[Tuple[str, Any]]]) -> None:
31+
cls.impl.load_config(settings)
32+
33+
def generate_csrf_tokens(self, secret_key: Optional[str] = None) -> Tuple[str, str]:
34+
return self.impl.generate_csrf_tokens(secret_key)
35+
36+
def get_csrf_from_body(self, data: bytes) -> str:
37+
return self.impl.get_csrf_from_body(data)
38+
39+
def get_csrf_from_headers(self, headers: Headers) -> str:
40+
return self.impl.get_csrf_from_headers(headers)
41+
42+
def set_csrf_cookie(self, csrf_signed_token: str, response: Response) -> None:
43+
self.impl.set_csrf_cookie(csrf_signed_token, response)
44+
45+
def unset_csrf_cookie(self, response: Response) -> None:
46+
self.impl.unset_csrf_cookie(response)
47+
48+
async def validate_csrf(
49+
self,
50+
request: Request,
51+
cookie_key: Optional[str] = None,
52+
secret_key: Optional[str] = None,
53+
time_limit: Optional[int] = None,
54+
) -> None:
55+
await self.impl.validate_csrf(request, cookie_key, secret_key, time_limit)
56+
2057

2158
__all__: Tuple[str, ...] = ("CsrfProtect",)
2259
__name__ = "fastapi-csrf-protect"

0 commit comments

Comments
 (0)