Skip to content

Commit 5d8cf1d

Browse files
authored
Merge pull request Calysto#156 from Calysto/replwrap-fix
Replwrap fixes
2 parents 97e3248 + d98b492 commit 5d8cf1d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

metakernel/pexpect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def spawn(command, args=[], timeout=30, maxread=2000,
2424
'''
2525
codec_errors = kwargs.get('codec_errors', kwargs.get('errors', 'strict'))
2626
if pty is None:
27-
if not isinstance(command, (list, tuple)):
28-
command = shlex.split(command, posix=False)
27+
command = shlex.split(command, posix=os.name == 'posix')
2928
command += args
3029
child = PopenSpawn(command, timeout=timeout, maxread=maxread,
3130
searchwindowsize=searchwindowsize,

metakernel/replwrap.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
if PY3:
1313
def u(s):
1414
return s
15+
basestring = str
1516
else:
1617
def u(s):
1718
if isinstance(s, str):
@@ -33,7 +34,6 @@ class REPLWrapper(object):
3334
:param cmd_or_spawn: This can either be an instance of
3435
:class:`pexpect.spawn` in which a REPL has already been started,
3536
or a str command to start a new REPL process.
36-
:param str args: The arguments to pass to the command
3737
:param str prompt_regex: Regular expression representing process prompt, eg ">>>" in Python.
3838
:param str continuation_prompt_regex: Regular expression repesenting process continuation prompt, e.g. "..." in Python.
3939
:param str prompt_change_cmd: Optional kernel command that sets continuation-of-line-prompts, eg PS1 and PS2, such as "..." in Python.
@@ -54,15 +54,14 @@ class REPLWrapper(object):
5454
"""
5555

5656
def __init__(self, cmd_or_spawn, prompt_regex, prompt_change_cmd,
57-
args=[],
5857
new_prompt_regex=PEXPECT_PROMPT,
5958
continuation_prompt_regex=PEXPECT_CONTINUATION_PROMPT,
6059
stdin_prompt_regex=PEXPECT_STDIN_PROMPT,
6160
extra_init_cmd=None,
6261
prompt_emit_cmd=None,
6362
echo=False):
64-
if isinstance(cmd_or_spawn, (str, list, tuple)):
65-
self.child = pexpect.spawnu(cmd_or_spawn, args=args, echo=echo,
63+
if isinstance(cmd_or_spawn, basestring):
64+
self.child = pexpect.spawnu(cmd_or_spawn, echo=echo,
6665
codec_errors="ignore",
6766
encoding="utf-8")
6867
else:
@@ -96,6 +95,7 @@ def __init__(self, cmd_or_spawn, prompt_regex, prompt_change_cmd,
9695

9796
self._stream_handler = None
9897
self._stdin_handler = None
98+
9999
self._expect_prompt()
100100

101101
if extra_init_cmd is not None:
@@ -159,10 +159,12 @@ def run_command(self, command, timeout=None, stream_handler=None,
159159
res = []
160160
self._stream_handler = stream_handler
161161
self._stdin_handler = stdin_handler
162+
162163
self.sendline(cmdlines[0])
163164
for line in cmdlines[1:]:
164-
self._expect_prompt(timeout=timeout)
165-
res.append(self.child.before)
165+
if not self.prompt_emit_cmd:
166+
self._expect_prompt(timeout=timeout)
167+
res.append(self.child.before)
166168
self.sendline(line)
167169

168170
# Command was fully submitted, now wait for the next prompt

0 commit comments

Comments
 (0)