Browse Source

🎨 Auto format

pull/15427/head
pre-commit-ci-lite[bot] 3 months ago
committed by GitHub
parent
commit
432d1e1a7f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      fastapi/sse.py
  2. 4
      tests/test_sse.py

5
fastapi/sse.py

@ -7,7 +7,7 @@ from annotated_doc import Doc
from pydantic import AfterValidator, BaseModel, Field, model_validator
from starlette.background import BackgroundTask
from starlette.responses import StreamingResponse
from starlette.types import Receive, Send, Scope
from starlette.types import Receive, Scope, Send
# Canonical SSE event schema matching the OpenAPI 3.2 spec
# (Section 4.14.4 "Special Considerations for Server-Sent Events")
@ -113,7 +113,6 @@ class EventSourceResponse(StreamingResponse):
Each item is expected to be a :class:`ServerSentEvent` (encoded
automatically) or already-raw bytes (passed through).
"""
from fastapi.sse import ServerSentEvent, format_sse_event
if hasattr(content, "__aiter__"):
async for item in content:
@ -386,7 +385,7 @@ class ServerSentEvent(BaseModel):
] = None
@model_validator(mode="after")
def _check_data_exclusive(self) -> "ServerSentEvent":
def _check_data_exclusive(self) -> ServerSentEvent:
if self.data is not None and self.raw_data is not None:
raise ValueError(
"Cannot set both 'data' and 'raw_data' on the same "

4
tests/test_sse.py

@ -355,9 +355,7 @@ def test_encode_comment():
def test_encode_raw():
"""encode_raw() places raw data without JSON encoding."""
result = EventSourceResponse.encode_raw(
raw_data="<div>hello</div>", event="html"
)
result = EventSourceResponse.encode_raw(raw_data="<div>hello</div>", event="html")
assert b"data: <div>hello</div>\n" in result
assert b'data: "<div>hello</div>"' not in result

Loading…
Cancel
Save