fix: HTML/JSON import failing (#7330)

This commit is contained in:
Michael Genson
2026-03-26 23:12:25 -05:00
committed by GitHub
parent 4dd8d836e1
commit 7c5913b012
5 changed files with 207 additions and 20 deletions

View File

@@ -1,3 +1,23 @@
import json
class MatchAny:
def __eq__(self, _: object) -> bool:
return True
def parse_sse_events(text: str) -> list[dict]:
"""Parse SSE response text into a list of events with 'event' and 'data' keys."""
events = []
current: dict = {}
for line in text.splitlines():
if line.startswith("event:"):
current["event"] = line[len("event:") :].strip()
elif line.startswith("data:"):
current["data"] = json.loads(line[len("data:") :].strip())
elif line == "" and current:
events.append(current)
current = {}
if current:
events.append(current)
return events