MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / iter_bytes

Method iter_bytes

src/anthropic/_streaming.py:349–357  ·  view source on GitHub ↗

Given an iterator that yields raw binary data, iterate over it & yield every event encountered

(self, iterator: Iterator[bytes])

Source from the content-addressed store, hash-verified

347 self._raw = []
348
349 def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
350 """Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
351 for chunk in self._iter_chunks(iterator):
352 # Split before decoding so splitlines() only uses \r and \n
353 for raw_line in chunk.splitlines():
354 line = raw_line.decode("utf-8")
355 sse = self.decode(line)
356 if sse:
357 yield sse
358
359 def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]:
360 """Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""

Callers 2

_iter_eventsMethod · 0.45
raw_eventsMethod · 0.45

Calls 2

_iter_chunksMethod · 0.95
decodeMethod · 0.95

Tested by

no test coverage detected