Replace sx_call() with render_to_sx() across all services
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m6s

Python no longer generates s-expression strings. All SX rendering now
goes through render_to_sx() which builds AST from native Python values
and evaluates via async_eval_to_sx() — no SX string literals in Python.

- Add render_to_sx()/render_to_html() infrastructure in shared/sx/helpers.py
- Add (abort status msg) IO primitive in shared/sx/primitives_io.py
- Convert all 9 services: ~650 sx_call() invocations replaced
- Convert shared helpers (root_header_sx, full_page_sx, etc.) to async
- Fix likes service import bug (likes.models → models)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 00:08:33 +00:00
parent 0554f8a113
commit e085fe43b4
51 changed files with 1824 additions and 1742 deletions

View File

@@ -13,9 +13,8 @@ from typing import Any
from markupsafe import escape
from shared.sx.jinja_bridge import load_service_components
from shared.sx.parser import serialize
from shared.sx.helpers import (
sx_call, SxExpr,
render_to_sx,
root_header_sx, full_page_sx, header_child_sx,
)
@@ -81,16 +80,16 @@ def _serialize_remote_actor(a) -> dict:
# Social page shell
# ---------------------------------------------------------------------------
def _social_page(ctx: dict, actor: Any, *, content: str,
async def _social_page(ctx: dict, actor: Any, *, content: str,
title: str = "Rose Ash", meta_html: str = "") -> str:
from shared.sx.parser import SxExpr
actor_data = _serialize_actor(actor)
nav = sx_call("federation-social-nav",
actor=SxExpr(serialize(actor_data)) if actor_data else None)
social_hdr = sx_call("federation-social-header", nav=SxExpr(nav))
hdr = root_header_sx(ctx)
child = header_child_sx(social_hdr)
nav = await render_to_sx("federation-social-nav", actor=actor_data)
social_hdr = await render_to_sx("federation-social-header", nav=SxExpr(nav))
hdr = await root_header_sx(ctx)
child = await header_child_sx(social_hdr)
header_rows = "(<> " + hdr + " " + child + ")"
return full_page_sx(ctx, header_rows=header_rows, content=content,
return await full_page_sx(ctx, header_rows=header_rows, content=content,
meta_html=meta_html or f'<title>{escape(title)}</title>')
@@ -99,24 +98,24 @@ def _social_page(ctx: dict, actor: Any, *, content: str,
# ---------------------------------------------------------------------------
async def render_federation_home(ctx: dict) -> str:
hdr = root_header_sx(ctx)
return full_page_sx(ctx, header_rows=hdr)
hdr = await root_header_sx(ctx)
return await full_page_sx(ctx, header_rows=hdr)
async def render_login_page(ctx: dict) -> str:
error = ctx.get("error", "")
email = ctx.get("email", "")
content = sx_call("account-login-content",
content = await render_to_sx("account-login-content",
error=error or None, email=str(escape(email)))
return _social_page(ctx, None, content=content, title="Login \u2014 Rose Ash")
return await _social_page(ctx, None, content=content, title="Login \u2014 Rose Ash")
async def render_check_email_page(ctx: dict) -> str:
email = ctx.get("email", "")
email_error = ctx.get("email_error")
content = sx_call("account-check-email-content",
content = await render_to_sx("account-check-email-content",
email=str(escape(email)), email_error=email_error)
return _social_page(ctx, None, content=content,
return await _social_page(ctx, None, content=content,
title="Check your email \u2014 Rose Ash")
@@ -124,6 +123,7 @@ async def render_choose_username_page(ctx: dict) -> str:
from shared.browser.app.csrf import generate_csrf_token
from quart import url_for
from shared.config import config
from shared.sx.parser import SxExpr
csrf = generate_csrf_token()
error = ctx.get("error", "")
@@ -132,15 +132,15 @@ async def render_choose_username_page(ctx: dict) -> str:
check_url = url_for("identity.check_username")
actor = ctx.get("actor")
error_sx = sx_call("auth-error-banner", error=error) if error else ""
content = sx_call(
error_sx = await render_to_sx("auth-error-banner", error=error) if error else ""
content = await render_to_sx(
"federation-choose-username",
domain=str(escape(ap_domain)),
error=SxExpr(error_sx) if error_sx else None,
csrf=csrf, username=str(escape(username)),
check_url=check_url,
)
return _social_page(ctx, actor, content=content,
return await _social_page(ctx, actor, content=content,
title="Choose Username \u2014 Rose Ash")
@@ -164,10 +164,10 @@ async def render_timeline_items(items: list, timeline_type: str,
else:
next_url = url_for(f"social.{timeline_type}_timeline_page", before=before)
return sx_call("federation-timeline-items",
items=SxExpr(serialize(item_dicts)),
return await render_to_sx("federation-timeline-items",
items=item_dicts,
timeline_type=timeline_type,
actor=SxExpr(serialize(actor_data)) if actor_data else None,
actor=actor_data,
next_url=next_url)
@@ -178,14 +178,14 @@ async def render_search_results(actors: list, query: str, page: int,
actor_data = _serialize_actor(actor)
parts = []
for ad in actor_dicts:
parts.append(sx_call("federation-actor-card-from-data",
a=SxExpr(serialize(ad)),
actor=SxExpr(serialize(actor_data)) if actor_data else None,
followed_urls=SxExpr(serialize(list(followed_urls))),
parts.append(await render_to_sx("federation-actor-card-from-data",
a=ad,
actor=actor_data,
followed_urls=list(followed_urls),
list_type="search"))
if len(actors) >= 20:
next_url = url_for("social.search_page", q=query, page=page + 1)
parts.append(sx_call("federation-scroll-sentinel", url=next_url))
parts.append(await render_to_sx("federation-scroll-sentinel", url=next_url))
return "(<> " + " ".join(parts) + ")" if parts else ""
@@ -195,14 +195,14 @@ async def render_following_items(actors: list, page: int, actor: Any) -> str:
actor_data = _serialize_actor(actor)
parts = []
for ad in actor_dicts:
parts.append(sx_call("federation-actor-card-from-data",
a=SxExpr(serialize(ad)),
actor=SxExpr(serialize(actor_data)) if actor_data else None,
followed_urls=SxExpr(serialize([])),
parts.append(await render_to_sx("federation-actor-card-from-data",
a=ad,
actor=actor_data,
followed_urls=[],
list_type="following"))
if len(actors) >= 20:
next_url = url_for("social.following_list_page", page=page + 1)
parts.append(sx_call("federation-scroll-sentinel", url=next_url))
parts.append(await render_to_sx("federation-scroll-sentinel", url=next_url))
return "(<> " + " ".join(parts) + ")" if parts else ""
@@ -213,14 +213,14 @@ async def render_followers_items(actors: list, page: int,
actor_data = _serialize_actor(actor)
parts = []
for ad in actor_dicts:
parts.append(sx_call("federation-actor-card-from-data",
a=SxExpr(serialize(ad)),
actor=SxExpr(serialize(actor_data)) if actor_data else None,
followed_urls=SxExpr(serialize(list(followed_urls))),
parts.append(await render_to_sx("federation-actor-card-from-data",
a=ad,
actor=actor_data,
followed_urls=list(followed_urls),
list_type="followers"))
if len(actors) >= 20:
next_url = url_for("social.followers_list_page", page=page + 1)
parts.append(sx_call("federation-scroll-sentinel", url=next_url))
parts.append(await render_to_sx("federation-scroll-sentinel", url=next_url))
return "(<> " + " ".join(parts) + ")" if parts else ""
@@ -233,13 +233,14 @@ async def render_actor_timeline_items(items: list, actor_id: int,
# Public API: POST handler fragment renderers
# ---------------------------------------------------------------------------
def render_interaction_buttons(object_id: str, author_inbox: str,
async def render_interaction_buttons(object_id: str, author_inbox: str,
like_count: int, boost_count: int,
liked_by_me: bool, boosted_by_me: bool,
actor: Any) -> str:
"""Render interaction buttons fragment for POST response."""
from shared.browser.app.csrf import generate_csrf_token
from quart import url_for
from shared.sx.parser import SxExpr
csrf = generate_csrf_token()
safe_id = object_id.replace("/", "_").replace(":", "_")
@@ -262,31 +263,31 @@ def render_interaction_buttons(object_id: str, author_inbox: str,
boost_cls = "hover:text-green-600"
reply_url = url_for("social.defpage_compose_form", reply_to=object_id) if object_id else ""
reply_sx = sx_call("federation-reply-link", url=reply_url) if reply_url else ""
reply_sx = await render_to_sx("federation-reply-link", url=reply_url) if reply_url else ""
like_form = sx_call("federation-like-form",
like_form = await render_to_sx("federation-like-form",
action=like_action, target=target, oid=object_id, ainbox=author_inbox,
csrf=csrf, cls=f"flex items-center gap-1 {like_cls}",
icon=like_icon, count=str(like_count))
boost_form = sx_call("federation-boost-form",
boost_form = await render_to_sx("federation-boost-form",
action=boost_action, target=target, oid=object_id, ainbox=author_inbox,
csrf=csrf, cls=f"flex items-center gap-1 {boost_cls}",
count=str(boost_count))
return sx_call("federation-interaction-buttons",
return await render_to_sx("federation-interaction-buttons",
like=SxExpr(like_form),
boost=SxExpr(boost_form),
reply=SxExpr(reply_sx) if reply_sx else None)
def render_actor_card(actor_dto: Any, actor: Any, followed_urls: set,
async def render_actor_card(actor_dto: Any, actor: Any, followed_urls: set,
*, list_type: str = "following") -> str:
"""Render a single actor card fragment for POST response."""
actor_data = _serialize_actor(actor)
ad = _serialize_remote_actor(actor_dto)
return sx_call("federation-actor-card-from-data",
a=SxExpr(serialize(ad)),
actor=SxExpr(serialize(actor_data)) if actor_data else None,
followed_urls=SxExpr(serialize(list(followed_urls))),
return await render_to_sx("federation-actor-card-from-data",
a=ad,
actor=actor_data,
followed_urls=list(followed_urls),
list_type=list_type)