MCPcopy Index your code
hub / github.com/bpython/bpython / FakeOutput

Class FakeOutput

bpython/curtsiesfrontend/coderunner.py:204–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202
203
204class FakeOutput:
205 def __init__(self, coderunner, on_write, real_fileobj):
206 """Fakes sys.stdout or sys.stderr
207
208 on_write should always take unicode
209
210 fileno should be the fileno that on_write will
211 output to (e.g. 1 for standard output).
212 """
213 self.coderunner = coderunner
214 self.on_write = on_write
215 self._real_fileobj = real_fileobj
216
217 def write(self, s, *args, **kwargs):
218 self.on_write(s, *args, **kwargs)
219 return self.coderunner.request_from_main_context(force_refresh=True)
220
221 # Some applications which use curses require that sys.stdout
222 # have a method called fileno. One example is pwntools. This
223 # is not a widespread issue, but is annoying.
224 def fileno(self):
225 return self._real_fileobj.fileno()
226
227 def writelines(self, l):
228 for s in l:
229 self.write(s)
230
231 def flush(self):
232 pass
233
234 def isatty(self):
235 return True
236
237 @property
238 def encoding(self):
239 return self._real_fileobj.encoding

Callers 4

test_simpleMethod · 0.90
test_exceptionMethod · 0.90
test_bytesMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 3

test_simpleMethod · 0.72
test_exceptionMethod · 0.72
test_bytesMethod · 0.72