Skip to content

Commit b544c79

Browse files
committed
fixes #827
1 parent 0c955cc commit b544c79

File tree

4 files changed

+12
-50
lines changed

4 files changed

+12
-50
lines changed

fasthtml/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ async def _find_p(req, arg:str, p:Parameter):
183183
if issubclass(anno, HtmxHeaders): return _get_htmx(req.headers)
184184
if issubclass(anno, Starlette): return req.scope['app']
185185
if _is_body(anno) and 'session'.startswith(arg.lower()): return req.scope.get('session', {})
186+
if issubclass(anno, State): return req.scope['app'].state
186187
if _is_body(anno): return await _from_body(req, p)
187188
# If there's no annotation, check for special names
188189
if anno is empty:
@@ -193,6 +194,7 @@ async def _find_p(req, arg:str, p:Parameter):
193194
if arg.lower()=='htmx': return _get_htmx(req.headers)
194195
if arg.lower()=='app': return req.scope['app']
195196
if arg.lower()=='body': return (await req.body()).decode()
197+
if arg.lower()=='state': return req.scope['app'].state
196198
if arg.lower() in ('hdrs','ftrs','bodykw','htmlkw'): return getattr(req, arg.lower())
197199
if arg!='resp': warn(f"`{arg} has no type annotation and is not a recognised special name, so is ignored.")
198200
return None

fasthtml/starlette.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from starlette.exceptions import HTTPException,WebSocketException
1717
from starlette.endpoints import HTTPEndpoint,WebSocketEndpoint
1818
from starlette.config import Config
19-
from starlette.datastructures import CommaSeparatedStrings, Secret, UploadFile, URLPath
19+
from starlette.datastructures import CommaSeparatedStrings, Secret, UploadFile, URLPath, State
2020
from starlette.types import ASGIApp, Receive, Scope, Send
2121
from starlette.concurrency import run_in_threadpool
2222
from starlette.background import BackgroundTask, BackgroundTasks

nbs/api/00_core.ipynb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
{
131131
"data": {
132132
"text/plain": [
133-
"datetime.datetime(2025, 11, 19, 14, 0)"
133+
"datetime.datetime(2026, 2, 6, 14, 0)"
134134
]
135135
},
136136
"execution_count": null,
@@ -743,6 +743,7 @@
743743
" if issubclass(anno, HtmxHeaders): return _get_htmx(req.headers)\n",
744744
" if issubclass(anno, Starlette): return req.scope['app']\n",
745745
" if _is_body(anno) and 'session'.startswith(arg.lower()): return req.scope.get('session', {})\n",
746+
" if issubclass(anno, State): return req.scope['app'].state\n",
746747
" if _is_body(anno): return await _from_body(req, p)\n",
747748
" # If there's no annotation, check for special names\n",
748749
" if anno is empty:\n",
@@ -753,6 +754,7 @@
753754
" if arg.lower()=='htmx': return _get_htmx(req.headers)\n",
754755
" if arg.lower()=='app': return req.scope['app']\n",
755756
" if arg.lower()=='body': return (await req.body()).decode()\n",
757+
" if arg.lower()=='state': return req.scope['app'].state\n",
756758
" if arg.lower() in ('hdrs','ftrs','bodykw','htmlkw'): return getattr(req, arg.lower())\n",
757759
" if arg!='resp': warn(f\"`{arg} has no type annotation and is not a recognised special name, so is ignored.\")\n",
758760
" return None\n",
@@ -786,12 +788,12 @@
786788
"name": "stdout",
787789
"output_type": "stream",
788790
"text": [
789-
"{'req': <starlette.requests.Request object>, 'this': <starlette.applications.Starlette object>, 'a': '1', 'b': HttpHeader(k='value1', v='value3')}\n"
791+
"{'req': <starlette.requests.Request object>, 'this': <starlette.applications.Starlette object>, 'a': '1', 'b': HttpHeader(k='value1', v='value3'), 'state': <starlette.datastructures.State object>}\n"
790792
]
791793
}
792794
],
793795
"source": [
794-
"def g(req, this:Starlette, a:str, b:HttpHeader): ...\n",
796+
"def g(req, this:Starlette, a:str, b:HttpHeader, state): ...\n",
795797
"\n",
796798
"async def f(req):\n",
797799
" a = await _wrap_req(req, _params(g))\n",
@@ -3953,14 +3955,6 @@
39533955
"#| hide\n",
39543956
"import nbdev; nbdev.nbdev_export()"
39553957
]
3956-
},
3957-
{
3958-
"cell_type": "code",
3959-
"execution_count": null,
3960-
"id": "bf47445c",
3961-
"metadata": {},
3962-
"outputs": [],
3963-
"source": []
39643958
}
39653959
],
39663960
"metadata": {},

nbs/api/08_oauth.ipynb

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -340,30 +340,10 @@
340340
"execution_count": null,
341341
"id": "b4dd67a9",
342342
"metadata": {},
343-
"outputs": [
344-
{
345-
"data": {
346-
"text/html": [
347-
"\n",
348-
"<script>\n",
349-
"document.body.addEventListener('htmx:configRequest', (event) => {\n",
350-
" if(event.detail.path.includes('://')) return;\n",
351-
" htmx.config.selfRequestsOnly=false;\n",
352-
" event.detail.path = `${location.protocol}//${location.hostname}:8000${event.detail.path}`;\n",
353-
"});\n",
354-
"</script>"
355-
],
356-
"text/plain": [
357-
"<IPython.core.display.HTML object>"
358-
]
359-
},
360-
"metadata": {},
361-
"output_type": "display_data"
362-
}
363-
],
343+
"outputs": [],
364344
"source": [
365-
"app,rt = fast_app()\n",
366-
"server = JupyUvi(app, port=port)"
345+
"# app,rt = fast_app()\n",
346+
"# server = JupyUvi(app, port=port)"
367347
]
368348
},
369349
{
@@ -915,23 +895,9 @@
915895
"#| hide\n",
916896
"import nbdev; nbdev.nbdev_export()"
917897
]
918-
},
919-
{
920-
"cell_type": "code",
921-
"execution_count": null,
922-
"id": "e0f7a90b",
923-
"metadata": {},
924-
"outputs": [],
925-
"source": []
926898
}
927899
],
928-
"metadata": {
929-
"kernelspec": {
930-
"display_name": "python3",
931-
"language": "python",
932-
"name": "python3"
933-
}
934-
},
900+
"metadata": {},
935901
"nbformat": 4,
936902
"nbformat_minor": 5
937903
}

0 commit comments

Comments
 (0)