You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add server-side formatting to sse (currently client-only).
encode_event(data="", *, event=None, id=None, retry=None) -> str — one complete SSE block, terminated by a blank line.
Multi-line data becomes one data: line per line; CRLF and lone CR are normalized to LF.
Empty data still emits data: so the block dispatches.
id must not contain NUL; retry must be a non-negative integer.
A comment/heartbeat helper (encode_comment) if it can be made unambiguous.
Optional SSEEvent.encode() convenience that delegates to encode_event.
Unit tests: field formatting, multi-line data, empty data, validation errors, round-trip through EventSource.
Docs (EN/ZH): a server-side example using httpserver.StreamingResponse with content_type="text/event-stream".
Bump sse 0.3.4 → 0.4.0; refresh manifest.json.
Why
httpserver has StreamingResponse but no SSE formatter. Users hand-roll the wire format and get the details wrong: multi-line data:, exactly one leading space after the colon, the blank line that dispatches, NUL in id, non-integer retry.
Acceptance
encode_event matches the WHATWG field syntax and round-trips through EventSource.
The encoder path imports neither httpserver nor httpclient (pure stdlib).
Tests and docs pass; manifest and version updated.
Activity