python-fasthtml 0.14.3__tar.gz → 0.14.4__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.
Files changed (39) hide show
  1. {python_fasthtml-0.14.3/python_fasthtml.egg-info → python_fasthtml-0.14.4}/PKG-INFO +1 -1
  2. python_fasthtml-0.14.4/fasthtml/__init__.py +2 -0
  3. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/_modidx.py +1 -0
  4. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/core.py +7 -6
  5. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/xtend.py +8 -1
  6. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4/python_fasthtml.egg-info}/PKG-INFO +1 -1
  7. python_fasthtml-0.14.3/fasthtml/__init__.py +0 -2
  8. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/CONTRIBUTING.md +0 -0
  9. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/LICENSE +0 -0
  10. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/MANIFEST.in +0 -0
  11. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/README.md +0 -0
  12. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/authmw.py +0 -0
  13. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/basics.py +0 -0
  14. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/cli.py +0 -0
  15. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/common.py +0 -0
  16. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/components.py +0 -0
  17. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/components.pyi +0 -0
  18. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/core.pyi +0 -0
  19. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/fastapp.py +0 -0
  20. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/ft.py +0 -0
  21. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/js.py +0 -0
  22. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/jupyter.py +0 -0
  23. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/katex.js +0 -0
  24. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/live_reload.py +0 -0
  25. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/oauth.py +0 -0
  26. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/pico.py +0 -0
  27. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/starlette.py +0 -0
  28. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/stripe_otp.py +0 -0
  29. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/svg.py +0 -0
  30. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/toaster.py +0 -0
  31. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/fasthtml/xtend.pyi +0 -0
  32. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/pyproject.toml +0 -0
  33. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/python_fasthtml.egg-info/SOURCES.txt +0 -0
  34. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/python_fasthtml.egg-info/dependency_links.txt +0 -0
  35. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/python_fasthtml.egg-info/entry_points.txt +0 -0
  36. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/python_fasthtml.egg-info/requires.txt +0 -0
  37. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/python_fasthtml.egg-info/top_level.txt +0 -0
  38. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/setup.cfg +0 -0
  39. {python_fasthtml-0.14.3 → python_fasthtml-0.14.4}/tests/test_toaster.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.14.3
3
+ Version: 0.14.4
4
4
  Summary: The fastest way to create an HTML app
5
5
  Author-email: Jeremy Howard and contributors <github@jhoward.fastmail.fm>
6
6
  License: Apache-2.0
@@ -0,0 +1,2 @@
1
+ __version__ = "0.14.4"
2
+ from .core import *
@@ -339,4 +339,5 @@ d = { 'settings': { 'branch': 'main',
339
339
  'fasthtml.xtend.sitemap_url': ('api/xtend.html#sitemap_url', 'fasthtml/xtend.py'),
340
340
  'fasthtml.xtend.sitemap_xml': ('api/xtend.html#sitemap_xml', 'fasthtml/xtend.py'),
341
341
  'fasthtml.xtend.undouble_braces': ('api/xtend.html#undouble_braces', 'fasthtml/xtend.py'),
342
+ 'fasthtml.xtend.upload_pb_attrs': ('api/xtend.html#upload_pb_attrs', 'fasthtml/xtend.py'),
342
343
  'fasthtml.xtend.with_sid': ('api/xtend.html#with_sid', 'fasthtml/xtend.py')}}}
@@ -157,7 +157,7 @@ DEF_MAXPART = 100*1024*1024
157
157
 
158
158
  # %% ../nbs/api/00_core.ipynb #42c9cea0
159
159
  async def parse_form(req: Request) -> FormData:
160
- "Starlette errors on empty multipart forms, so this checks for that situation"
160
+ "Starlette errors on empty multipart/json forms, so this checks for that situation"
161
161
  ctype = req.headers.get("Content-Type", "")
162
162
  maxpart = getattr(req, "max_part_size", DEF_MAXPART)
163
163
  if ctype.startswith("multipart/form-data"):
@@ -165,8 +165,9 @@ async def parse_form(req: Request) -> FormData:
165
165
  except IndexError: raise HTTPException(400, "Invalid form-data: no boundary")
166
166
  if int(req.headers.get("Content-Length", "0")) <= len(boundary) + 6: return FormData()
167
167
  return await req.form(max_part_size=maxpart)
168
- await req.body() # Cache body for non-multipart request types
169
- return await req.json() if ctype == 'application/json' else await req.form(max_part_size=maxpart)
168
+ body = await req.body() # Cache body for non-multipart request types
169
+ if ctype == 'application/json': return await req.json() if body else {}
170
+ return await req.form(max_part_size=maxpart)
170
171
 
171
172
  # %% ../nbs/api/00_core.ipynb #0caedd04
172
173
  async def _from_body(conn, p, data):
@@ -458,7 +459,7 @@ def _is_ft_resp(resp):
458
459
  # %% ../nbs/api/00_core.ipynb #968d9245
459
460
  def _resp(req, resp, cls=empty, status_code=200):
460
461
  "Create appropriate HTTP response from request and response data"
461
- if not resp: resp=''
462
+ if resp is None: resp=''
462
463
  if hasattr(resp, '__response__'): resp = resp.__response__(req)
463
464
  if not (isinstance(cls, type) and issubclass(cls, Response)): cls=empty
464
465
  if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)
@@ -916,14 +917,14 @@ reg_re_param("static", '|'.join(_static_exts))
916
917
  @patch
917
918
  def static_route_exts(self:FastHTML, prefix='/', static_path='.', exts='static'):
918
919
  "Add a static route at URL path `prefix` with files from `static_path` and `exts` defined by `reg_re_param()`"
919
- @self.route(f"{prefix}{{fname:path}}.{{ext:{exts}}}")
920
+ @self.get(f"{prefix}{{fname:path}}.{{ext:{exts}}}")
920
921
  async def get(fname:str, ext:str): return FileResponse(f'{static_path}/{fname}.{ext}')
921
922
 
922
923
  # %% ../nbs/api/00_core.ipynb #b31de65a
923
924
  @patch
924
925
  def static_route(self:FastHTML, ext='', prefix='/', static_path='.'):
925
926
  "Add a static route at URL path `prefix` with files from `static_path` and single `ext` (including the '.')"
926
- @self.route(f"{prefix}{{fname:path}}{ext}")
927
+ @self.get(f"{prefix}{{fname:path}}{ext}")
927
928
  async def get(fname:str): return FileResponse(f'{static_path}/{fname}{ext}')
928
929
 
929
930
  # %% ../nbs/api/00_core.ipynb #f63b7a03
@@ -9,7 +9,7 @@ __all__ = ['sid_scr', 'A', 'AX', 'Form', 'Hidden', 'CheckboxX', 'Script', 'Style
9
9
  'loose_format', 'ScriptX', 'replace_css_vars', 'StyleX', 'Nbsp', 'Surreal', 'On', 'Prev', 'Now', 'AnyNow',
10
10
  'run_js', 'HtmxOn', 'jsd', 'Fragment', 'Titled', 'Socials', 'YouTubeEmbed', 'Favicon', 'clear', 'with_sid',
11
11
  'LdJson', 'LdContactPoint', 'LdOrg', 'LdWebsite', 'LdCourseInstance', 'LdCourse', 'robots_txt',
12
- 'sitemap_url', 'sitemap_xml']
12
+ 'sitemap_url', 'sitemap_xml', 'upload_pb_attrs']
13
13
 
14
14
  # %% ../nbs/api/02_xtend.ipynb #8e2d405b
15
15
  from dataclasses import dataclass, asdict
@@ -349,3 +349,10 @@ def sitemap_xml(app, urls, loc_base=""):
349
349
  def get():
350
350
  urlset = [sitemap_url(url_info, loc_base) for url_info in urls]
351
351
  return Urlset(*urlset, xmlns="http://www.sitemaps.org/schemas/sitemap/0.9")
352
+
353
+ # %% ../nbs/api/02_xtend.ipynb #6a1990ed
354
+ def upload_pb_attrs(id='uploadprog'):
355
+ "Form `hx_on` progress attr that reveals and updates a hidden `upload_pb` of matching `id`"
356
+ js = """{ const p=document.getElementById('%s');
357
+ if(event.detail.total) {p.classList.remove('hidden'); p.value=event.detail.loaded/event.detail.total*100} }""" % id
358
+ return {'hx-on::xhr:progress': js}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.14.3
3
+ Version: 0.14.4
4
4
  Summary: The fastest way to create an HTML app
5
5
  Author-email: Jeremy Howard and contributors <github@jhoward.fastmail.fm>
6
6
  License: Apache-2.0
@@ -1,2 +0,0 @@
1
- __version__ = "0.14.3"
2
- from .core import *