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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user