python-fasthtml 0.12.16__tar.gz → 0.12.17__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 (42) hide show
  1. {python_fasthtml-0.12.16/python_fasthtml.egg-info → python_fasthtml-0.12.17}/PKG-INFO +1 -1
  2. python_fasthtml-0.12.17/fasthtml/__init__.py +2 -0
  3. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/_modidx.py +2 -1
  4. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/core.py +34 -19
  5. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17/python_fasthtml.egg-info}/PKG-INFO +1 -1
  6. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/settings.ini +1 -1
  7. python_fasthtml-0.12.16/fasthtml/__init__.py +0 -2
  8. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/CONTRIBUTING.md +0 -0
  9. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/LICENSE +0 -0
  10. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/MANIFEST.in +0 -0
  11. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/README.md +0 -0
  12. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/authmw.py +0 -0
  13. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/basics.py +0 -0
  14. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/cli.py +0 -0
  15. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/common.py +0 -0
  16. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/components.py +0 -0
  17. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/components.pyi +0 -0
  18. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/core.pyi +0 -0
  19. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/fastapp.py +0 -0
  20. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/ft.py +0 -0
  21. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/js.py +0 -0
  22. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/jupyter.py +0 -0
  23. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/katex.js +0 -0
  24. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/live_reload.py +0 -0
  25. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/oauth.py +0 -0
  26. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/pico.py +0 -0
  27. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/starlette.py +0 -0
  28. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/stripe_otp.py +0 -0
  29. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/svg.py +0 -0
  30. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/toaster.py +0 -0
  31. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/xtend.py +0 -0
  32. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/fasthtml/xtend.pyi +0 -0
  33. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/pyproject.toml +0 -0
  34. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/python_fasthtml.egg-info/SOURCES.txt +0 -0
  35. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/python_fasthtml.egg-info/dependency_links.txt +0 -0
  36. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/python_fasthtml.egg-info/entry_points.txt +0 -0
  37. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/python_fasthtml.egg-info/not-zip-safe +0 -0
  38. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/python_fasthtml.egg-info/requires.txt +0 -0
  39. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/python_fasthtml.egg-info/top_level.txt +0 -0
  40. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/setup.cfg +0 -0
  41. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/setup.py +0 -0
  42. {python_fasthtml-0.12.16 → python_fasthtml-0.12.17}/tests/test_toaster.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.12.16
3
+ Version: 0.12.17
4
4
  Summary: The fastest way to create an HTML app
5
5
  Home-page: https://github.com/AnswerDotAI/fasthtml
6
6
  Author: Jeremy Howard and contributors
@@ -0,0 +1,2 @@
1
+ __version__ = "0.12.17"
2
+ from .core import *
@@ -90,6 +90,7 @@ d = { 'settings': { 'branch': 'main',
90
90
  'fasthtml.core._mk_list': ('api/core.html#_mk_list', 'fasthtml/core.py'),
91
91
  'fasthtml.core._mk_locfunc': ('api/core.html#_mk_locfunc', 'fasthtml/core.py'),
92
92
  'fasthtml.core._params': ('api/core.html#_params', 'fasthtml/core.py'),
93
+ 'fasthtml.core._part_resp': ('api/core.html#_part_resp', 'fasthtml/core.py'),
93
94
  'fasthtml.core._resp': ('api/core.html#_resp', 'fasthtml/core.py'),
94
95
  'fasthtml.core._send_ws': ('api/core.html#_send_ws', 'fasthtml/core.py'),
95
96
  'fasthtml.core._to_htmx_header': ('api/core.html#_to_htmx_header', 'fasthtml/core.py'),
@@ -101,7 +102,6 @@ d = { 'settings': { 'branch': 'main',
101
102
  'fasthtml.core._wrap_ws': ('api/core.html#_wrap_ws', 'fasthtml/core.py'),
102
103
  'fasthtml.core._ws_endp': ('api/core.html#_ws_endp', 'fasthtml/core.py'),
103
104
  'fasthtml.core._xt_cts': ('api/core.html#_xt_cts', 'fasthtml/core.py'),
104
- 'fasthtml.core._xt_resp': ('api/core.html#_xt_resp', 'fasthtml/core.py'),
105
105
  'fasthtml.core.cookie': ('api/core.html#cookie', 'fasthtml/core.py'),
106
106
  'fasthtml.core.decode_uri': ('api/core.html#decode_uri', 'fasthtml/core.py'),
107
107
  'fasthtml.core.def_hdrs': ('api/core.html#def_hdrs', 'fasthtml/core.py'),
@@ -109,6 +109,7 @@ d = { 'settings': { 'branch': 'main',
109
109
  'fasthtml.core.flat_xt': ('api/core.html#flat_xt', 'fasthtml/core.py'),
110
110
  'fasthtml.core.form2dict': ('api/core.html#form2dict', 'fasthtml/core.py'),
111
111
  'fasthtml.core.get_key': ('api/core.html#get_key', 'fasthtml/core.py'),
112
+ 'fasthtml.core.is_full_page': ('api/core.html#is_full_page', 'fasthtml/core.py'),
112
113
  'fasthtml.core.nested_name': ('api/core.html#nested_name', 'fasthtml/core.py'),
113
114
  'fasthtml.core.noop_body': ('api/core.html#noop_body', 'fasthtml/core.py'),
114
115
  'fasthtml.core.parse_form': ('api/core.html#parse_form', 'fasthtml/core.py'),
@@ -7,8 +7,8 @@ __all__ = ['empty', 'htmx_hdrs', 'fh_cfg', 'htmx_resps', 'htmx_exts', 'htmxsrc',
7
7
  'charset', 'cors_allow', 'iframe_scr', 'all_meths', 'devtools_loc', 'parsed_date', 'snake2hyphens',
8
8
  'HtmxHeaders', 'HttpHeader', 'HtmxResponseHeaders', 'form2dict', 'parse_form', 'JSONResponse', 'flat_xt',
9
9
  'Beforeware', 'EventStream', 'signal_shutdown', 'uri', 'decode_uri', 'flat_tuple', 'noop_body', 'respond',
10
- 'Redirect', 'get_key', 'qp', 'def_hdrs', 'FastHTML', 'nested_name', 'serve', 'Client', 'RouteFuncs',
11
- 'APIRouter', 'cookie', 'reg_re_param', 'MiddlewareBase', 'FtResponse', 'unqid', 'setup_ws']
10
+ 'is_full_page', 'Redirect', 'get_key', 'qp', 'def_hdrs', 'FastHTML', 'nested_name', 'serve', 'Client',
11
+ 'RouteFuncs', 'APIRouter', 'cookie', 'reg_re_param', 'MiddlewareBase', 'FtResponse', 'unqid', 'setup_ws']
12
12
 
13
13
  # %% ../nbs/api/00_core.ipynb
14
14
  import json,uuid,inspect,types,signal,asyncio,threading,inspect
@@ -389,25 +389,35 @@ def respond(req, heads, bdy):
389
389
  return Html(Head(*heads, *flat_xt(req.hdrs)), body, **req.htmlkw)
390
390
 
391
391
  # %% ../nbs/api/00_core.ipynb
392
- def _xt_cts(req, resp):
392
+ def is_full_page(req, resp):
393
+ is_frag = 'hx-request' in req.headers and 'hx-history-restore-request' not in req.headers
394
+ return (resp and not is_frag and not any(getattr(o, 'tag', '')=='html' for o in resp))
395
+
396
+ # %% ../nbs/api/00_core.ipynb
397
+ def _part_resp(req, resp):
393
398
  resp = flat_tuple(resp)
394
399
  resp = resp + tuple(getattr(req, 'injects', ()))
395
400
  http_hdrs,resp = partition(resp, risinstance(HttpHeader))
396
- http_hdrs = {o.k:str(o.v) for o in http_hdrs}
397
401
  tasks,resp = partition(resp, risinstance(BackgroundTask))
398
- ts = BackgroundTasks()
399
- for t in tasks: ts.tasks.append(t)
402
+ kw = {"headers": {"vary": "HX-Request, HX-History-Restore-Request"}}
403
+ if http_hdrs: kw['headers'] |= {o.k:str(o.v) for o in http_hdrs}
404
+ if tasks:
405
+ ts = BackgroundTasks()
406
+ for t in tasks: ts.tasks.append(t)
407
+ kw['background'] = ts
408
+ resp = tuple(resp)
409
+ if len(resp)==1: resp = resp[0]
410
+ return resp,kw
411
+
412
+ # %% ../nbs/api/00_core.ipynb
413
+ def _xt_cts(req, resp):
400
414
  hdr_tags = 'title','meta','link','style','base'
415
+ resp = tuplify(resp)
401
416
  heads,bdy = partition(resp, lambda o: getattr(o, 'tag', '') in hdr_tags)
402
- if resp and 'hx-request' not in req.headers and not any(getattr(o, 'tag', '')=='html' for o in resp):
417
+ if is_full_page(req, resp):
403
418
  title = [] if any(getattr(o, 'tag', '')=='title' for o in heads) else [Title(req.app.title)]
404
419
  resp = respond(req, [*heads, *title], bdy)
405
- return _to_xml(req, resp, indent=fh_cfg.indent), http_hdrs, ts
406
-
407
- # %% ../nbs/api/00_core.ipynb
408
- def _xt_resp(req, resp, status_code):
409
- cts,http_hdrs,tasks = _xt_cts(req, resp)
410
- return HTMLResponse(cts, status_code=status_code, headers=http_hdrs, background=tasks)
420
+ return _to_xml(req, resp, indent=fh_cfg.indent)
411
421
 
412
422
  # %% ../nbs/api/00_core.ipynb
413
423
  def _is_ft_resp(resp): return isinstance(resp, _iter_typs+(HttpHeader,FT)) or hasattr(resp, '__ft__')
@@ -418,15 +428,18 @@ def _resp(req, resp, cls=empty, status_code=200):
418
428
  if hasattr(resp, '__response__'): resp = resp.__response__(req)
419
429
  if cls in (Any,FT): cls=empty
420
430
  if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)
421
- if cls is not empty: return cls(resp, status_code=status_code)
422
- if isinstance(resp, Response): return resp # respect manually set status_code
423
- if _is_ft_resp(resp): return _xt_resp(req, resp, status_code)
431
+ resp,kw = _part_resp(req, resp)
432
+ if cls is not empty: return cls(resp, status_code=status_code, **kw)
433
+ if isinstance(resp, Response): return resp
434
+ if _is_ft_resp(resp):
435
+ cts = _xt_cts(req, resp)
436
+ return HTMLResponse(cts, status_code=status_code, **kw)
424
437
  if isinstance(resp, str): cls = HTMLResponse
425
438
  elif isinstance(resp, Mapping): cls = JSONResponse
426
439
  else:
427
440
  resp = str(resp)
428
441
  cls = HTMLResponse
429
- return cls(resp, status_code=status_code)
442
+ return cls(resp, status_code=status_code, **kw)
430
443
 
431
444
  # %% ../nbs/api/00_core.ipynb
432
445
  class Redirect:
@@ -788,8 +801,10 @@ class FtResponse:
788
801
  self.cls,self.media_type,self.background = cls,media_type,background
789
802
 
790
803
  def __response__(self, req):
791
- cts,httphdrs,tasks = _xt_cts(req, self.content)
792
- if not tasks.tasks: tasks = self.background
804
+ resp,kw = _part_resp(req, self.content)
805
+ cts = _xt_cts(req, resp)
806
+ tasks,httphdrs = kw.get('background'),kw.get('headers')
807
+ if not tasks: tasks = self.background
793
808
  headers = {**(self.headers or {}), **httphdrs}
794
809
  return self.cls(cts, status_code=self.status_code, headers=headers, media_type=self.media_type, background=tasks)
795
810
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fasthtml
3
- Version: 0.12.16
3
+ Version: 0.12.17
4
4
  Summary: The fastest way to create an HTML app
5
5
  Home-page: https://github.com/AnswerDotAI/fasthtml
6
6
  Author: Jeremy Howard and contributors
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = fasthtml
3
3
  lib_name = python-fasthtml
4
- version = 0.12.16
4
+ version = 0.12.17
5
5
  min_python = 3.10
6
6
  license = apache2
7
7
  requirements = fastcore>=1.8.1 python-dateutil starlette>0.33 oauthlib itsdangerous uvicorn[standard]>=0.30 httpx fastlite>=0.1.1 python-multipart beautifulsoup4
@@ -1,2 +0,0 @@
1
- __version__ = "0.12.16"
2
- from .core import *