Skip to content

Commit c816865

Browse files
add more methods to fake stdin/err/out
1 parent d796bca commit c816865

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

bpython/curtsiesfrontend/coderunner.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ def __init__(self, coderunner, please):
115115
def write(self, *args, **kwargs):
116116
self.please(*args, **kwargs)
117117
return self.coderunner.refresh_and_get_value()
118+
def writelines(self, l):
119+
for s in l:
120+
self.write(s)
121+
def flush(self):
122+
pass
123+
def isatty(self):
124+
return True
118125

119126
def test_simple():
120127
orig_stdout = sys.stdout

bpython/curtsiesfrontend/repl.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import greenlet
88
import subprocess
99
import tempfile
10+
import errno
1011

1112
from bpython.autocomplete import Autocomplete, SIMPLE
1213
from bpython.repl import Repl as BpythonRepl
@@ -90,6 +91,26 @@ def readline(self):
9091
self.readline_results.append(value)
9192
return value
9293

94+
def readlines(self, size=-1):
95+
return list(iter(self.readline, ''))
96+
97+
def __iter__(self):
98+
return iter(self.readlines())
99+
100+
def isatty(self):
101+
return True
102+
103+
def flush(self):
104+
"""Flush the internal buffer. This is a no-op. Flushing stdin
105+
doesn't make any sense anyway."""
106+
107+
def write(self, value):
108+
# XXX IPython expects sys.stdin.write to exist, there will no doubt be
109+
# others, so here's a hack to keep them happy
110+
raise IOError(errno.EBADF, "sys.stdin is read-only")
111+
112+
#TODO write a read() method
113+
93114
class ReevaluateFakeStdin(object):
94115
def __init__(self, fakestdin, repl):
95116
self.fakestdin = fakestdin

0 commit comments

Comments
 (0)