MCPcopy
hub / github.com/docker/docker-py / consume_socket_output

Function consume_socket_output

docker/utils/socket.py:140–174  ·  view source on GitHub ↗

Iterate through frames read from the socket and return the result. Args: demux (bool): If False, stdout and stderr are multiplexed, and the result is the concatenation of all the frames. If True, the streams are demultiplexed, and the result is

(frames, demux=False)

Source from the content-addressed store, hash-verified

138
139
140def consume_socket_output(frames, demux=False):
141 """
142 Iterate through frames read from the socket and return the result.
143
144 Args:
145
146 demux (bool):
147 If False, stdout and stderr are multiplexed, and the result is the
148 concatenation of all the frames. If True, the streams are
149 demultiplexed, and the result is a 2-tuple where each item is the
150 concatenation of frames belonging to the same stream.
151 """
152 if demux is False:
153 # If the streams are multiplexed, the generator returns strings, that
154 # we just need to concatenate.
155 return b"".join(frames)
156
157 # If the streams are demultiplexed, the generator yields tuples
158 # (stdout, stderr)
159 out = [None, None]
160 for frame in frames:
161 # It is guaranteed that for each frame, one and only one stream
162 # is not None.
163 assert frame != (None, None)
164 if frame[0] is not None:
165 if out[0] is None:
166 out[0] = frame[0]
167 else:
168 out[0] += frame[0]
169 else:
170 if out[1] is None:
171 out[1] = frame[1]
172 else:
173 out[1] += frame[1]
174 return tuple(out)
175
176
177def demux_adaptor(stream_id, data):

Callers 1

_read_from_socketMethod · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected