11"""The `FastHTML` subclass of `Starlette`, along with the `RouterX` and `RouteX` classes it automatically uses."""
2- __all__ = ['empty' , 'htmx_hdrs' , 'fh_cfg' , 'htmx_resps' , 'htmx_exts' , 'htmxsrc' , 'fhjsscr' , 'surrsrc' , 'scopesrc' , 'viewport' , 'charset' , 'cors_allow' , 'iframe_scr' , 'all_meths' , 'parsed_date' , 'snake2hyphens' , 'HtmxHeaders' , 'HttpHeader' , 'HtmxResponseHeaders' , 'form2dict' , 'parse_form' , 'flat_xt' , 'Beforeware' , 'EventStream' , 'signal_shutdown' , 'uri' , 'decode_uri' , 'flat_tuple' , 'noop_body' , 'respond' , 'Redirect' , 'get_key' , 'def_hdrs' , 'FastHTML' , 'serve' , 'Client' , 'APIRouter' , 'cookie' , 'reg_re_param' , 'MiddlewareBase' , 'FtResponse' , 'unqid' , 'setup_ws' ]
3- import json , uuid , inspect , types , uvicorn , signal , asyncio , threading
2+ __all__ = ['empty' , 'htmx_hdrs' , 'fh_cfg' , 'htmx_resps' , 'htmx_exts' , 'htmxsrc' , 'fhjsscr' , 'surrsrc' , 'scopesrc' , 'viewport' , 'charset' , 'cors_allow' , 'iframe_scr' , 'all_meths' , 'parsed_date' , 'snake2hyphens' , 'HtmxHeaders' , 'HttpHeader' , 'HtmxResponseHeaders' , 'form2dict' , 'parse_form' , 'flat_xt' , 'Beforeware' , 'EventStream' , 'signal_shutdown' , 'uri' , 'decode_uri' , 'flat_tuple' , 'noop_body' , 'respond' , 'Redirect' , 'get_key' , 'qp' , ' def_hdrs' , 'FastHTML' , 'nested_name' , ' serve' , 'Client' , 'RouteFuncs ' , 'APIRouter' , 'cookie' , 'reg_re_param' , 'MiddlewareBase' , 'FtResponse' , 'unqid' , 'setup_ws' ]
3+ import json , uuid , inspect , types , uvicorn , signal , asyncio , threading , inspect
44from fastcore .utils import *
55from fastcore .xml import *
66from fastcore .meta import use_kwargs_dict
@@ -167,6 +167,7 @@ def _apply_ft(o):
167167
168168def _to_xml (req , resp , indent ):
169169 ...
170+ _iter_typs = (tuple , list , map , filter , range , types .GeneratorType )
170171
171172def flat_tuple (o ):
172173 """Flatten lists"""
@@ -203,9 +204,9 @@ class Redirect:
203204
204205async def _wrap_call (f , req , params ):
205206 ...
206- htmx_exts = {
'head-support' :
'https://unpkg.com/[email protected] .1 /head-support.js' ,
'preload' :
'https://unpkg.com/htmx-ext-preload@2.0.1 /preload.js' ,
'class-tools' :
'https://unpkg.com/[email protected] /class-tools.js' ,
'loading-states' :
'https://unpkg.com/[email protected] /loading-states.js' ,
'multi-swap' :
'https://unpkg.com/[email protected] /multi-swap.js' ,
'path-deps' :
'https://unpkg.com/[email protected] /path-deps.js' ,
'remove-me' :
'https://unpkg.com/[email protected] /remove-me.js' ,
'ws' :
'https://unpkg.com/htmx-ext-ws/ws.js' ,
'chunked-transfer' :
'https://unpkg.com/htmx-ext-transfer-encoding-chunked/transfer-encoding-chunked.js' }
207- htmxsrc = Script (src = 'https://unpkg.com/htmx.org@next /dist/htmx.min.js' )
208- fhjsscr = Script (
src = 'https://cdn.jsdelivr.net/gh/answerdotai/[email protected] .4 /fasthtml.js' )
207+ htmx_exts = {
'head-support' :
'https://unpkg.com/[email protected] .3 /head-support.js' ,
'preload' :
'https://unpkg.com/htmx-ext-preload@2.1.0 /preload.js' ,
'class-tools' :
'https://unpkg.com/[email protected] /class-tools.js' ,
'loading-states' :
'https://unpkg.com/[email protected] /loading-states.js' ,
'multi-swap' :
'https://unpkg.com/[email protected] /multi-swap.js' ,
'path-deps' :
'https://unpkg.com/[email protected] /path-deps.js' ,
'remove-me' :
'https://unpkg.com/[email protected] /remove-me.js' ,
'ws' :
'https://unpkg.com/htmx-ext-ws@2.0.2 /ws.js' ,
'chunked-transfer' :
'https://unpkg.com/htmx-ext-transfer-encoding-chunked@0.4.0 /transfer-encoding-chunked.js' }
208+ htmxsrc = Script (src = 'https://unpkg.com/htmx.org@2.0.4 /dist/htmx.min.js' )
209+ fhjsscr = Script (
src = 'https://cdn.jsdelivr.net/gh/answerdotai/[email protected] .12 /fasthtml.js' )
209210surrsrc = Script (src = 'https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js' )
210211scopesrc = Script (src = 'https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js' )
211212viewport = Meta (name = 'viewport' , content = 'width=device-width, initial-scale=1, viewport-fit=cover' )
@@ -220,7 +221,8 @@ def _list(o):
220221def _wrap_ex (f , hdrs , ftrs , htmlkw , bodykw , body_wrap ):
221222 ...
222223
223- def _mk_locfunc (f , p ):
224+ def qp (p : str , ** kw ) -> str :
225+ """Add query parameters to path p"""
224226 ...
225227
226228def def_hdrs (htmx = True , surreal = True ):
@@ -231,7 +233,7 @@ iframe_scr = Script(NotStr("\n function sendmsg() {\n window.parent.po
231233
232234class FastHTML (Starlette ):
233235
234- def __init__ (self , debug = False , routes = None , middleware = None , exception_handlers = None , on_startup = None , on_shutdown = None , lifespan = None , hdrs = None , ftrs = None , exts = None , before = None , after = None , surreal = True , htmx = True , default_hdrs = True , sess_cls = SessionMiddleware , secret_key = None , session_cookie = 'session_' , max_age = 365 * 24 * 3600 , sess_path = '/' , same_site = 'lax' , sess_https_only = False , sess_domain = None , key_fname = '.sesskey' , body_wrap = noop_body , htmlkw = None , nb_hdrs = True , ** bodykw ):
236+ def __init__ (self , debug = False , routes = None , middleware = None , title : str = 'FastHTML page' , exception_handlers = None , on_startup = None , on_shutdown = None , lifespan = None , hdrs = None , ftrs = None , exts = None , before = None , after = None , surreal = True , htmx = True , default_hdrs = True , sess_cls = SessionMiddleware , secret_key = None , session_cookie = 'session_' , max_age = 365 * 24 * 3600 , sess_path = '/' , same_site = 'lax' , sess_https_only = False , sess_domain = None , key_fname = '.sesskey' , body_wrap = noop_body , htmlkw = None , nb_hdrs = False , ** bodykw ):
235237 ...
236238
237239 def add_route (self , route ):
@@ -250,7 +252,7 @@ class FastHTML(Starlette):
250252 def _add_route (self , func , path , methods , name , include_in_schema , body_wrap ):
251253 ...
252254
253- def route (self , path : str = None , methods = None , name = None , include_in_schema = True , body_wrap = noop_body ):
255+ def route (self , path : str = None , methods = None , name = None , include_in_schema = True , body_wrap = None ):
254256 """Add a route at `path`"""
255257 ...
256258
@@ -262,6 +264,13 @@ class FastHTML(Starlette):
262264 """Add a static route at URL path `prefix` with files from `static_path` and single `ext` (including the '.')"""
263265 ...
264266all_meths = 'get post put delete patch head trace options' .split ()
267+
268+ def _mk_locfunc (f , p ):
269+ ...
270+
271+ def nested_name (f ):
272+ """Get name of function `f` using '_' to join nested function names"""
273+ ...
265274for o in all_meths :
266275 setattr (FastHTML , o , partialmethod (FastHTML .route , methods = o ))
267276
@@ -280,21 +289,41 @@ class Client:
280289for o in ('get' , 'post' , 'delete' , 'put' , 'patch' , 'options' ):
281290 setattr (Client , o , partialmethod (Client ._sync , o ))
282291
292+ class RouteFuncs :
293+
294+ def __init__ (self ):
295+ ...
296+
297+ def __setattr__ (self , name , value ):
298+ ...
299+
300+ def __getattr__ (self , name ):
301+ ...
302+
303+ def __dir__ (self ):
304+ ...
305+
283306class APIRouter :
284307 """Add routes to an app"""
285308
286- def __init__ (self ):
309+ def __init__ (self , prefix : str | None = None , body_wrap = noop_body ):
287310 ...
288311
289- def __call__ (self : FastHTML , path : str = None , methods = None , name = None , include_in_schema = True , body_wrap = noop_body ):
312+ def _wrap_func (self , func , path = None ):
313+ ...
314+
315+ def __call__ (self , path : str = None , methods = None , name = None , include_in_schema = True , body_wrap = None ):
290316 """Add a route at `path`"""
291317 ...
292318
319+ def __getattr__ (self , name ):
320+ ...
321+
293322 def to_app (self , app ):
294323 """Add routes to `app`"""
295324 ...
296325
297- def ws (self : FastHTML , path : str , conn = None , disconn = None , name = None , middleware = None ):
326+ def ws (self , path : str , conn = None , disconn = None , name = None , middleware = None ):
298327 """Add a websocket route at `path`"""
299328 ...
300329for o in all_meths :
@@ -307,7 +336,7 @@ def cookie(key: str, value='', max_age=None, expires=None, path='/', domain=None
307336def reg_re_param (m , s ):
308337 ...
309338reg_re_param ('path' , '.*?' )
310- reg_re_param ('static' , 'ico|gif|jpg|jpeg|webm|css|js|woff|png|svg|mp4|webp|ttf|otf|eot|woff2|txt|html|map' )
339+ reg_re_param ('static' , 'ico|gif|jpg|jpeg|webm|css|js|woff|png|svg|mp4|webp|ttf|otf|eot|woff2|txt|html|map|pdf ' )
311340
312341class MiddlewareBase :
313342
0 commit comments