fasthx 2.2.0__tar.gz → 2.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fasthx-2.2.0 → fasthx-2.2.1}/PKG-INFO +1 -1
- fasthx-2.2.1/fasthx/dependencies.py +47 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/pyproject.toml +1 -1
- fasthx-2.2.0/fasthx/dependencies.py +0 -47
- {fasthx-2.2.0 → fasthx-2.2.1}/LICENSE +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/README.md +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/__init__.py +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/component_selectors.py +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/core_decorators.py +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/htmy.py +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/jinja.py +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/py.typed +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/typing.py +0 -0
- {fasthx-2.2.0 → fasthx-2.2.1}/fasthx/utils.py +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from collections.abc import Mapping
|
|
2
|
+
from typing import TYPE_CHECKING, Annotated, Any, TypeAlias
|
|
3
|
+
|
|
4
|
+
from fastapi import Depends, Header
|
|
5
|
+
from fastapi import Request as FARequest
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
Request: TypeAlias = FARequest
|
|
9
|
+
else:
|
|
10
|
+
Request: TypeAlias = Mapping[str, Any]
|
|
11
|
+
"""
|
|
12
|
+
Alias for `Request` arguments.
|
|
13
|
+
|
|
14
|
+
Workaround for this FastAPI bug: https://github.com/fastapi/fastapi/discussions/12403.
|
|
15
|
+
And here's a FastAPI bugfix: https://github.com/fastapi/fastapi/pull/12406.
|
|
16
|
+
|
|
17
|
+
This workaround should be removed when FastAPI had several new releases with the fix.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_hx_request(
|
|
22
|
+
request: FARequest, hx_request: Annotated[str | None, Header()] = None
|
|
23
|
+
) -> Request | None:
|
|
24
|
+
"""
|
|
25
|
+
FastAPI dependency that returns the current request if it is an HTMX one,
|
|
26
|
+
i.e. it contains an `"HX-Request: true"` header.
|
|
27
|
+
"""
|
|
28
|
+
return request if hx_request == "true" else None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_page_request(request: FARequest) -> Request:
|
|
32
|
+
"""
|
|
33
|
+
Replacement dependency for `Request` to work around this FastAPI bug:
|
|
34
|
+
https://github.com/fastapi/fastapi/discussions/12403.
|
|
35
|
+
"""
|
|
36
|
+
return request
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
DependsHXRequest = Annotated[Request | None, Depends(get_hx_request)]
|
|
40
|
+
"""Annotated type (dependency) for `get_hx_request()` for FastAPI."""
|
|
41
|
+
|
|
42
|
+
DependsPageRequest = Annotated[Request, Depends(get_page_request)]
|
|
43
|
+
"""
|
|
44
|
+
Annotated `Request` dependency alias.
|
|
45
|
+
|
|
46
|
+
Workaround for this FastAPI bug: https://github.com/fastapi/fastapi/discussions/12403
|
|
47
|
+
"""
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
from collections.abc import Mapping
|
|
2
|
-
from typing import TYPE_CHECKING, Annotated, Any, TypeAlias
|
|
3
|
-
|
|
4
|
-
from fastapi import Depends, Header, Request
|
|
5
|
-
|
|
6
|
-
RequestAlias: TypeAlias = Mapping[str, Any]
|
|
7
|
-
"""
|
|
8
|
-
Alias for `Request` arguments.
|
|
9
|
-
|
|
10
|
-
Workaround for this FastAPI bug: https://github.com/fastapi/fastapi/discussions/12403.
|
|
11
|
-
And here's a FastAPI bugfix: https://github.com/fastapi/fastapi/pull/12406.
|
|
12
|
-
|
|
13
|
-
This workaround should be removed when FastAPI had several new releases with the fix.
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def get_hx_request(
|
|
18
|
-
request: Request, hx_request: Annotated[str | None, Header()] = None
|
|
19
|
-
) -> RequestAlias | None:
|
|
20
|
-
"""
|
|
21
|
-
FastAPI dependency that returns the current request if it is an HTMX one,
|
|
22
|
-
i.e. it contains an `"HX-Request: true"` header.
|
|
23
|
-
"""
|
|
24
|
-
return request if hx_request == "true" else None
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def get_page_request(request: Request) -> RequestAlias:
|
|
28
|
-
"""
|
|
29
|
-
Replacement dependency for `Request` to work around this FastAPI bug:
|
|
30
|
-
https://github.com/fastapi/fastapi/discussions/12403.
|
|
31
|
-
"""
|
|
32
|
-
return request
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if TYPE_CHECKING:
|
|
36
|
-
DependsHXRequest: TypeAlias = Request | None
|
|
37
|
-
DependsPageRequest: TypeAlias = Request
|
|
38
|
-
else:
|
|
39
|
-
DependsHXRequest = Annotated[RequestAlias | Request | None, Depends(get_hx_request)]
|
|
40
|
-
"""Annotated type (dependency) for `get_hx_request()` for FastAPI."""
|
|
41
|
-
|
|
42
|
-
DependsPageRequest = Annotated[RequestAlias | Request, Depends(get_page_request)]
|
|
43
|
-
"""
|
|
44
|
-
Annotated `Request` dependency alias.
|
|
45
|
-
|
|
46
|
-
Workaround for this FastAPI bug: https://github.com/fastapi/fastapi/discussions/12403
|
|
47
|
-
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|