Extract HTML5 SSE helpers
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 12:27:22 +03:00
parent 7b5893e5a8
commit 990eeedaba
3 changed files with 44 additions and 16 deletions
@@ -0,0 +1,19 @@
from __future__ import annotations
from collections.abc import Iterator
def html5_sse_event(event: str, fragment: str) -> str:
data = "\n".join(f"data: {line}" for line in fragment.splitlines())
return f"event: {event}\nretry: 5000\n{data}\n\n"
def html5_sse_if_changed(last_fragments: dict[str, str], event: str, fragment: str) -> Iterator[str]:
if last_fragments.get(event) == fragment:
return
last_fragments[event] = fragment
yield html5_sse_event(event, fragment)
def html5_sse_comment(message: str) -> str:
return f": {message}\n\n"