Skip to content

Commit 91009e4

Browse files
support filenos as args for readline wrapper
1 parent 88d04ec commit 91009e4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pyrepl/readline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ class _ReadlineWrapper(object):
182182
startup_hook = None
183183
config = ReadlineConfig()
184184

185-
def __init__(self):
186-
self.f_in = os.dup(0)
187-
self.f_out = os.dup(1)
185+
def __init__(self, f_in=None, f_out=None):
186+
self.f_in = f_in if f_in is not None else os.dup(0)
187+
self.f_out = f_out if f_out is not None else os.dup(1)
188188

189189
def get_reader(self):
190190
if self.reader is None:

testing/test_readline.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55

66
def test_raw_input():
7-
readline_wrapper = _ReadlineWrapper()
87
master, slave = pty.openpty()
9-
readline_wrapper.f_in = slave
8+
readline_wrapper = _ReadlineWrapper(slave, slave)
109
os.write(master, b'input\n')
11-
result = readline_wrapper.raw_input('prompt:')
10+
11+
result = readline_wrapper.get_reader().readline()
12+
#result = readline_wrapper.raw_input('prompt:')
1213
assert result == 'input'
1314
# A bytes string on python2, a unicode string on python3.
1415
assert isinstance(result, str)

0 commit comments

Comments
 (0)