MCPcopy Index your code
hub / github.com/docker/docker-py / split_buffer

Function split_buffer

docker/utils/json_stream.py:50–74  ·  view source on GitHub ↗

Given a generator which yields strings and a splitter function, joins all input, splits on the separator and yields each chunk. Unlike string.split(), each chunk includes the trailing separator, except for the last one if none was found on the end of the input.

(stream, splitter=None, decoder=lambda a: a)

Source from the content-addressed store, hash-verified

48
49
50def split_buffer(stream, splitter=None, decoder=lambda a: a):
51 """Given a generator which yields strings and a splitter function,
52 joins all input, splits on the separator and yields each chunk.
53 Unlike string.split(), each chunk includes the trailing
54 separator, except for the last one if none was found on the end
55 of the input.
56 """
57 splitter = splitter or line_splitter
58 buffered = ''
59
60 for data in stream_as_text(stream):
61 buffered += data
62 while True:
63 buffer_split = splitter(buffered)
64 if buffer_split is None:
65 break
66
67 item, buffered = buffer_split
68 yield item
69
70 if buffered:
71 try:
72 yield decoder(buffered)
73 except Exception as e:
74 raise StreamParseError(e) from e

Callers 1

json_streamFunction · 0.85

Calls 2

stream_as_textFunction · 0.85
StreamParseErrorClass · 0.85

Tested by

no test coverage detected