MCPcopy
hub / github.com/pyodide/pyodide / MemoryBIO

Class MemoryBIO

src/py/_ssl.py:161–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159
160
161class MemoryBIO:
162 def __init__(self):
163 self._buffer = bytearray()
164 self._eof = False
165
166 def write(self, data):
167 if isinstance(data, str):
168 raise TypeError("a bytes-like object is required, not 'str'")
169 if data is None:
170 raise TypeError("a bytes-like object is required, not 'NoneType'")
171 if isinstance(data, (bool, int)):
172 raise TypeError(
173 f"a bytes-like object is required, not '{type(data).__name__}'"
174 )
175 if isinstance(data, memoryview):
176 if not data.c_contiguous:
177 raise BufferError("memoryview must be contiguous")
178 data = data.tobytes()
179 self._buffer.extend(data)
180 return len(data)
181
182 def read(self, n=-1):
183 if n == -1 or n >= len(self._buffer):
184 data = bytes(self._buffer)
185 self._buffer.clear()
186 else:
187 data = bytes(self._buffer[:n])
188 del self._buffer[:n]
189 return data
190
191 @property
192 def eof(self):
193 return self._eof and len(self._buffer) == 0
194
195 def write_eof(self):
196 self._eof = True
197
198 @property
199 def pending(self):
200 return len(self._buffer)
201
202
203def txt2obj(txt, name=False):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…