python-fasthtml 0.4.4__tar.gz → 0.4.5__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.
- {python-fasthtml-0.4.4/python_fasthtml.egg-info → python-fasthtml-0.4.5}/PKG-INFO +1 -1
- python-fasthtml-0.4.5/fasthtml/__init__.py +2 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/cli.py +4 -3
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/components.py +1 -1
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/core.py +25 -21
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/core.pyi +13 -8
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5/python_fasthtml.egg-info}/PKG-INFO +1 -1
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/settings.ini +1 -1
- python-fasthtml-0.4.4/fasthtml/__init__.py +0 -2
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/CONTRIBUTING.md +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/LICENSE +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/MANIFEST.in +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/README.md +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/_modidx.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/authmw.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/basics.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/common.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/components.pyi +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/fastapp.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/ft.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/js.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/katex.js +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/live_reload.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/oauth.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/pico.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/starlette.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/svg.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/toaster.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/xtend.py +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/fasthtml/xtend.pyi +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/python_fasthtml.egg-info/SOURCES.txt +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/python_fasthtml.egg-info/dependency_links.txt +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/python_fasthtml.egg-info/entry_points.txt +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/python_fasthtml.egg-info/not-zip-safe +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/python_fasthtml.egg-info/requires.txt +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/python_fasthtml.egg-info/top_level.txt +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/setup.cfg +0 -0
- {python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/setup.py +0 -0
|
@@ -39,9 +39,10 @@ def railway_deploy(
|
|
|
39
39
|
assert nm=='railwayapp', f'Unexpected railway version string: {nm}'
|
|
40
40
|
if ver2tuple(ver)<(3,8): return print("Please update your railway CLI version to 3.8 or higher")
|
|
41
41
|
cp = run("railway status --json".split(), capture_output=True)
|
|
42
|
-
if not cp.returncode:
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if not cp.returncode:
|
|
43
|
+
print("Checking deployed projects...")
|
|
44
|
+
project_name = json.loads(cp.stdout.decode()).get('name')
|
|
45
|
+
if project_name == name: return print("This project is already deployed. Run `railway open`.")
|
|
45
46
|
reqs = Path('requirements.txt')
|
|
46
47
|
if not reqs.exists(): reqs.write_text('python-fasthtml')
|
|
47
48
|
_run(f"railway init -n {name}".split())
|
|
@@ -146,7 +146,7 @@ def html2ft(html, attr1st=False):
|
|
|
146
146
|
def _parse(elm, lvl=0, indent=4):
|
|
147
147
|
if isinstance(elm, str): return repr(elm.strip()) if elm.strip() else ''
|
|
148
148
|
if isinstance(elm, list): return '\n'.join(_parse(o, lvl) for o in elm)
|
|
149
|
-
tag_name = elm.name.capitalize()
|
|
149
|
+
tag_name = elm.name.capitalize().replace("-", "_")
|
|
150
150
|
if tag_name=='[document]': return _parse(list(elm.children), lvl)
|
|
151
151
|
cts = elm.contents
|
|
152
152
|
cs = [repr(c.strip()) if isinstance(c, str) else _parse(c, lvl+1)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/00_core.ipynb.
|
|
2
2
|
|
|
3
3
|
# %% auto 0
|
|
4
|
-
__all__ = ['empty', 'htmx_hdrs', 'fh_cfg', 'htmxscr', 'htmxwsscr', 'surrsrc', 'scopesrc', 'viewport', 'charset',
|
|
5
|
-
'date', 'snake2hyphens', 'HtmxHeaders', 'str2int', 'HttpHeader', 'form2dict', 'flat_xt',
|
|
6
|
-
'WS_RouteX', 'uri', 'decode_uri', 'flat_tuple', 'RouteX', 'RouterX', 'get_key', 'FastHTML',
|
|
7
|
-
'cookie', 'reg_re_param', 'MiddlewareBase']
|
|
4
|
+
__all__ = ['empty', 'htmx_hdrs', 'fh_cfg', 'htmxscr', 'htmxwsscr', 'fhjsscr', 'surrsrc', 'scopesrc', 'viewport', 'charset',
|
|
5
|
+
'all_meths', 'date', 'snake2hyphens', 'HtmxHeaders', 'str2int', 'HttpHeader', 'form2dict', 'flat_xt',
|
|
6
|
+
'Beforeware', 'WS_RouteX', 'uri', 'decode_uri', 'flat_tuple', 'RouteX', 'RouterX', 'get_key', 'FastHTML',
|
|
7
|
+
'serve', 'cookie', 'reg_re_param', 'MiddlewareBase']
|
|
8
8
|
|
|
9
9
|
# %% ../nbs/api/00_core.ipynb
|
|
10
10
|
import json,uuid,inspect,types,uvicorn
|
|
@@ -401,6 +401,7 @@ class RouterX(Router):
|
|
|
401
401
|
# %% ../nbs/api/00_core.ipynb
|
|
402
402
|
htmxscr = Script(src="https://unpkg.com/htmx.org@next/dist/htmx.min.js")
|
|
403
403
|
htmxwsscr = Script(src="https://unpkg.com/htmx-ext-ws/ws.js")
|
|
404
|
+
fhjsscr = Script(src="https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@main/fasthtml.js")
|
|
404
405
|
surrsrc = Script(src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js")
|
|
405
406
|
scopesrc = Script(src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js")
|
|
406
407
|
viewport = Meta(name="viewport", content="width=device-width, initial-scale=1, viewport-fit=cover")
|
|
@@ -456,7 +457,7 @@ class FastHTML(Starlette):
|
|
|
456
457
|
if default_hdrs:
|
|
457
458
|
if surreal: hdrs = [surrsrc,scopesrc] + hdrs
|
|
458
459
|
if ws_hdr: hdrs = [htmxwsscr] + hdrs
|
|
459
|
-
if htmx: hdrs = [htmxscr] + hdrs
|
|
460
|
+
if htmx: hdrs = [htmxscr,fhjsscr] + hdrs
|
|
460
461
|
hdrs = [charset, viewport] + hdrs
|
|
461
462
|
excs = {k:_wrap_ex(v, hdrs, ftrs, htmlkw, bodykw) for k,v in (exception_handlers or {}).items()}
|
|
462
463
|
super().__init__(debug, routes, middleware, excs, on_startup, on_shutdown, lifespan=lifespan)
|
|
@@ -470,24 +471,27 @@ class FastHTML(Starlette):
|
|
|
470
471
|
return func
|
|
471
472
|
return f
|
|
472
473
|
|
|
473
|
-
def route(self, path:str=None, methods=None, name=None, include_in_schema=True):
|
|
474
|
-
"Add a route at `path`"
|
|
475
|
-
pathstr = None if callable(path) else path
|
|
476
|
-
def f(func):
|
|
477
|
-
n,fn,p = name,func.__name__,pathstr
|
|
478
|
-
assert path or (fn not in _verbs), "Must provide a path when using http verb-based function name"
|
|
479
|
-
if methods: m = [methods] if isinstance(methods,str) else methods
|
|
480
|
-
else: m = [fn] if fn in _verbs else ['get','post']
|
|
481
|
-
if not n: n = fn
|
|
482
|
-
if not p: p = '/'+('' if fn=='index' else fn)
|
|
483
|
-
self.router.add_route(p, func, methods=m, name=n, include_in_schema=include_in_schema)
|
|
484
|
-
lf = _mk_locfunc(func, p)
|
|
485
|
-
lf.__routename__ = n
|
|
486
|
-
return lf
|
|
487
|
-
return f(path) if callable(path) else f
|
|
488
|
-
|
|
489
474
|
# %% ../nbs/api/00_core.ipynb
|
|
490
475
|
all_meths = 'get post put delete patch head trace options'.split()
|
|
476
|
+
|
|
477
|
+
@patch
|
|
478
|
+
def route(self:FastHTML, path:str=None, methods=None, name=None, include_in_schema=True):
|
|
479
|
+
"Add a route at `path`"
|
|
480
|
+
pathstr = None if callable(path) else path
|
|
481
|
+
def f(func):
|
|
482
|
+
n,fn,p = name,func.__name__,pathstr
|
|
483
|
+
assert path or (fn not in all_meths), "Must provide a path when using http verb-based function name"
|
|
484
|
+
if methods: m = [methods] if isinstance(methods,str) else methods
|
|
485
|
+
else: m = [fn] if fn in all_meths else ['get','post']
|
|
486
|
+
if not n: n = fn
|
|
487
|
+
if not p: p = '/'+('' if fn=='index' else fn)
|
|
488
|
+
self.router.add_route(p, func, methods=m, name=n, include_in_schema=include_in_schema)
|
|
489
|
+
lf = _mk_locfunc(func, p)
|
|
490
|
+
lf.__routename__ = n
|
|
491
|
+
return lf
|
|
492
|
+
return f(path) if callable(path) else f
|
|
493
|
+
|
|
494
|
+
# %% ../nbs/api/00_core.ipynb
|
|
491
495
|
for o in all_meths: setattr(FastHTML, o, partialmethod(FastHTML.route, methods=o))
|
|
492
496
|
|
|
493
497
|
# %% ../nbs/api/00_core.ipynb
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__all__ = ['empty', 'htmx_hdrs', 'fh_cfg', 'htmxscr', 'htmxwsscr', 'surrsrc', 'scopesrc', 'viewport', 'charset', 'all_meths', 'date', 'snake2hyphens', 'HtmxHeaders', 'str2int', 'HttpHeader', 'form2dict', 'flat_xt', 'Beforeware', 'WS_RouteX', 'uri', 'decode_uri', 'RouteX', 'RouterX', 'get_key', 'FastHTML', 'serve', 'cookie', 'reg_re_param', 'MiddlewareBase']
|
|
1
|
+
__all__ = ['empty', 'htmx_hdrs', 'fh_cfg', 'htmxscr', 'htmxwsscr', 'fhjsscr', 'surrsrc', 'scopesrc', 'viewport', 'charset', 'all_meths', 'date', 'snake2hyphens', 'HtmxHeaders', 'str2int', 'HttpHeader', 'form2dict', 'flat_xt', 'Beforeware', 'WS_RouteX', 'uri', 'decode_uri', 'flat_tuple', 'RouteX', 'RouterX', 'get_key', 'FastHTML', 'serve', 'cookie', 'reg_re_param', 'MiddlewareBase']
|
|
2
2
|
import json, uuid, inspect, types, uvicorn
|
|
3
3
|
from fastcore.utils import *
|
|
4
4
|
from fastcore.xml import *
|
|
@@ -152,6 +152,10 @@ def _apply_ft(o):
|
|
|
152
152
|
def _to_xml(req, resp, indent):
|
|
153
153
|
...
|
|
154
154
|
|
|
155
|
+
def flat_tuple(o):
|
|
156
|
+
"""Flatten lists"""
|
|
157
|
+
...
|
|
158
|
+
|
|
155
159
|
def _xt_resp(req, resp):
|
|
156
160
|
...
|
|
157
161
|
|
|
@@ -181,6 +185,7 @@ class RouterX(Router):
|
|
|
181
185
|
...
|
|
182
186
|
htmxscr = Script(src='https://unpkg.com/htmx.org@next/dist/htmx.min.js')
|
|
183
187
|
htmxwsscr = Script(src='https://unpkg.com/htmx-ext-ws/ws.js')
|
|
188
|
+
fhjsscr = Script(src='https://cdn.jsdelivr.net/gh/answerdotai/fasthtml-js@main/fasthtml.js')
|
|
184
189
|
surrsrc = Script(src='https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js')
|
|
185
190
|
scopesrc = Script(src='https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js')
|
|
186
191
|
viewport = Meta(name='viewport', content='width=device-width, initial-scale=1, viewport-fit=cover')
|
|
@@ -195,21 +200,21 @@ def _list(o):
|
|
|
195
200
|
def _wrap_ex(f, hdrs, ftrs, htmlkw, bodykw):
|
|
196
201
|
...
|
|
197
202
|
|
|
203
|
+
def _mk_locfunc(f, p):
|
|
204
|
+
...
|
|
205
|
+
|
|
198
206
|
class FastHTML(Starlette):
|
|
199
207
|
|
|
200
208
|
def __init__(self, debug=False, routes=None, middleware=None, exception_handlers=None, on_startup=None, on_shutdown=None, lifespan=None, hdrs=None, ftrs=None, before=None, after=None, ws_hdr=False, 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', htmlkw=None, **bodykw):
|
|
201
209
|
...
|
|
202
210
|
|
|
203
211
|
def ws(self, path: str, conn=None, disconn=None, name=None):
|
|
212
|
+
"""Add a websocket route at `path`"""
|
|
204
213
|
...
|
|
205
214
|
|
|
206
|
-
def
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
@patch
|
|
210
|
-
def route(self: FastHTML, path: str=None, methods=None, name=None, include_in_schema=True):
|
|
211
|
-
"""Add a route at `path`; the function name is the default method"""
|
|
212
|
-
...
|
|
215
|
+
def route(self, path: str=None, methods=None, name=None, include_in_schema=True):
|
|
216
|
+
"""Add a route at `path`"""
|
|
217
|
+
...
|
|
213
218
|
all_meths = 'get post put delete patch head trace options'.split()
|
|
214
219
|
for o in all_meths:
|
|
215
220
|
setattr(FastHTML, o, partialmethod(FastHTML.route, methods=o))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[DEFAULT]
|
|
2
2
|
repo = fasthtml
|
|
3
3
|
lib_name = fasthtml
|
|
4
|
-
version = 0.4.
|
|
4
|
+
version = 0.4.5
|
|
5
5
|
min_python = 3.10
|
|
6
6
|
license = apache2
|
|
7
7
|
requirements = fastcore>=1.7.1 python-dateutil starlette>0.33 oauthlib itsdangerous uvicorn[standard]>=0.30 httpx fastlite>=0.0.9 python-multipart beautifulsoup4
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
{python-fasthtml-0.4.4 → python-fasthtml-0.4.5}/python_fasthtml.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|