Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks
(self, iterator: Iterator[bytes])
| 303 | yield sse |
| 304 | |
| 305 | def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]: |
| 306 | """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks""" |
| 307 | data = b"" |
| 308 | for chunk in iterator: |
| 309 | for line in chunk.splitlines(keepends=True): |
| 310 | data += line |
| 311 | if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")): |
| 312 | yield data |
| 313 | data = b"" |
| 314 | if data: |
| 315 | yield data |
| 316 | |
| 317 | async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]: |
| 318 | """Given an iterator that yields raw binary data, iterate over it & yield every event encountered""" |