Fix examples.sx: paren balance + dict eval crash at startup

1. Extra closing paren in ex-tabs handler
2. tab-content dict values contained (div ...) HTML tags which crash
   during register_components since HTML primitives aren't in env

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 01:30:21 +00:00
parent c23d0888ea
commit 17c58a2b5b
10 changed files with 110 additions and 1103 deletions

View File

@@ -561,3 +561,15 @@ def prim_into(target: Any, coll: Any) -> Any:
return result
raise ValueError(f"into: unsupported target type {type(target).__name__}")
@register_primitive("random-int")
def prim_random_int(low: int, high: int) -> int:
import random
return random.randint(int(low), int(high))
@register_primitive("json-encode")
def prim_json_encode(value) -> str:
import json
return json.dumps(value, indent=2)

View File

@@ -408,6 +408,18 @@ async def _io_request_form_all(
return dict(form)
@register_io_handler("request-form-list")
async def _io_request_form_list(
args: list[Any], kwargs: dict[str, Any], ctx: RequestContext
) -> list:
"""``(request-form-list "field")`` → all values for a multi-value form field."""
if not args:
raise ValueError("request-form-list requires a field name")
from quart import request
form = await request.form
return form.getlist(str(args[0]))
@register_io_handler("request-headers-all")
async def _io_request_headers_all(
args: list[Any], kwargs: dict[str, Any], ctx: RequestContext

View File

@@ -202,6 +202,13 @@
:doc "All form fields as a dict."
:context :request)
(define-io-primitive "request-form-list"
:params (field-name)
:returns "list"
:async true
:doc "All values for a multi-value form field as a list."
:context :request)
(define-io-primitive "request-headers-all"
:params ()
:returns "dict"

View File

@@ -70,6 +70,17 @@
:doc "Modulo a % b."
:body (native-mod a b))
(define-primitive "random-int"
:params ((low :as number) (high :as number))
:returns "number"
:doc "Random integer in [low, high] inclusive."
:body (native-random-int low high))
(define-primitive "json-encode"
:params (value)
:returns "string"
:doc "Encode value as JSON string with indentation.")
(define-primitive "sqrt"
:params ((x :as number))
:returns "number"