MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / peekIntoStream

Function peekIntoStream

pager_lib/pyasn1/codec/streaming.py:151–184  ·  view source on GitHub ↗

Peek into stream. Parameters ---------- substrate: :py:class:`IOBase` Stream to read from. size: :py:class:`int` How many bytes to peek (-1 = all available) Returns ------- : :py:class:`bytes` or :py:class:`str` The return type depends on Python

(substrate, size=-1)

Source from the content-addressed store, hash-verified

149
150
151def peekIntoStream(substrate, size=-1):
152 """Peek into stream.
153
154 Parameters
155 ----------
156 substrate: :py:class:`IOBase`
157 Stream to read from.
158
159 size: :py:class:`int`
160 How many bytes to peek (-1 = all available)
161
162 Returns
163 -------
164 : :py:class:`bytes` or :py:class:`str`
165 The return type depends on Python major version
166 """
167 if hasattr(substrate, "peek"):
168 received = substrate.peek(size)
169 if received is None:
170 yield
171
172 while len(received) < size:
173 yield
174
175 yield received
176
177 else:
178 current_position = substrate.tell()
179 try:
180 for chunk in readFromStream(substrate, size):
181 yield chunk
182
183 finally:
184 substrate.seek(current_position)
185
186
187def readFromStream(substrate, size=-1, context=None):

Callers 1

valueDecoderMethod · 0.90

Calls 4

readFromStreamFunction · 0.85
peekMethod · 0.80
tellMethod · 0.80
seekMethod · 0.80

Tested by

no test coverage detected