12
12
if PY3 :
13
13
def u (s ):
14
14
return s
15
+ basestring = str
15
16
else :
16
17
def u (s ):
17
18
if isinstance (s , str ):
@@ -33,7 +34,6 @@ class REPLWrapper(object):
33
34
:param cmd_or_spawn: This can either be an instance of
34
35
:class:`pexpect.spawn` in which a REPL has already been started,
35
36
or a str command to start a new REPL process.
36
- :param str args: The arguments to pass to the command
37
37
:param str prompt_regex: Regular expression representing process prompt, eg ">>>" in Python.
38
38
:param str continuation_prompt_regex: Regular expression repesenting process continuation prompt, e.g. "..." in Python.
39
39
: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):
54
54
"""
55
55
56
56
def __init__ (self , cmd_or_spawn , prompt_regex , prompt_change_cmd ,
57
- args = [],
58
57
new_prompt_regex = PEXPECT_PROMPT ,
59
58
continuation_prompt_regex = PEXPECT_CONTINUATION_PROMPT ,
60
59
stdin_prompt_regex = PEXPECT_STDIN_PROMPT ,
61
60
extra_init_cmd = None ,
62
61
prompt_emit_cmd = None ,
63
62
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 ,
66
65
codec_errors = "ignore" ,
67
66
encoding = "utf-8" )
68
67
else :
@@ -96,6 +95,7 @@ def __init__(self, cmd_or_spawn, prompt_regex, prompt_change_cmd,
96
95
97
96
self ._stream_handler = None
98
97
self ._stdin_handler = None
98
+
99
99
self ._expect_prompt ()
100
100
101
101
if extra_init_cmd is not None :
@@ -159,10 +159,12 @@ def run_command(self, command, timeout=None, stream_handler=None,
159
159
res = []
160
160
self ._stream_handler = stream_handler
161
161
self ._stdin_handler = stdin_handler
162
+
162
163
self .sendline (cmdlines [0 ])
163
164
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 )
166
168
self .sendline (line )
167
169
168
170
# Command was fully submitted, now wait for the next prompt
0 commit comments