MCPcopy
hub / github.com/pyodide/pyodide / _WriteStream

Class _WriteStream

src/py/pyodide/console.py:65–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64
65class _WriteStream(_Stream):
66 def __init__(
67 self,
68 write_handler: Callable[[str], int | None],
69 name: str,
70 encoding: str = "utf-8",
71 errors: str = "strict",
72 ):
73 super().__init__(name, encoding, errors)
74 self._write_handler = write_handler
75
76 def writable(self) -> bool:
77 return True
78
79 def write(self, s: str) -> int:
80 if self.closed:
81 raise ValueError("write to closed file")
82 s = str.encode(s, self.encoding, self.errors).decode(self.encoding, self.errors)
83 written = self._write_handler(s)
84 if written is None:
85 # They didn't tell us how much they wrote, assume it was the whole string
86 return len(s)
87 return written
88
89
90class _ReadStream(_Stream):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…