##// END OF EJS Templates
Changes to pexpect so it does what we need after conversion to Python 3.
Thomas Kluyver -
Show More
@@ -229,16 +229,16 b' def run (command, timeout=-1, withexitstatus=False, events=None, extra_args=None'
229 while 1:
229 while 1:
230 try:
230 try:
231 index = child.expect (patterns)
231 index = child.expect (patterns)
232 if type(child.after) in types.StringTypes:
232 if isinstance(child.after, basestring):
233 child_result_list.append(child.before + child.after)
233 child_result_list.append(child.before + child.after)
234 else: # child.after may have been a TIMEOUT or EOF, so don't cat those.
234 else: # child.after may have been a TIMEOUT or EOF, so don't cat those.
235 child_result_list.append(child.before)
235 child_result_list.append(child.before)
236 if type(responses[index]) in types.StringTypes:
236 if isinstance(responses[index], basestring):
237 child.send(responses[index])
237 child.send(responses[index])
238 elif type(responses[index]) is types.FunctionType:
238 elif isinstance(responses[index], types.FunctionType):
239 callback_result = responses[index](locals())
239 callback_result = responses[index](locals())
240 sys.stdout.flush()
240 sys.stdout.flush()
241 if type(callback_result) in types.StringTypes:
241 if isinstance(callback_result, basestring):
242 child.send(callback_result)
242 child.send(callback_result)
243 elif callback_result:
243 elif callback_result:
244 break
244 break
@@ -399,7 +399,7 b' class spawn (object):'
399 self.logfile_read = None # input from child (read_nonblocking)
399 self.logfile_read = None # input from child (read_nonblocking)
400 self.logfile_send = None # output to send (send, sendline)
400 self.logfile_send = None # output to send (send, sendline)
401 self.maxread = maxread # max bytes to read at one time into buffer
401 self.maxread = maxread # max bytes to read at one time into buffer
402 self.buffer = '' # This is the read buffer. See maxread.
402 self.buffer = b'' # This is the read buffer. See maxread.
403 self.searchwindowsize = searchwindowsize # Anything before searchwindowsize point is preserved, but not searched.
403 self.searchwindowsize = searchwindowsize # Anything before searchwindowsize point is preserved, but not searched.
404 # Most Linux machines don't like delaybeforesend to be below 0.03 (30 ms).
404 # Most Linux machines don't like delaybeforesend to be below 0.03 (30 ms).
405 self.delaybeforesend = 0.05 # Sets sleep time used just before sending data to child. Time in seconds.
405 self.delaybeforesend = 0.05 # Sets sleep time used just before sending data to child. Time in seconds.
@@ -828,7 +828,7 b' class spawn (object):'
828 except OSError, e: # Linux does this
828 except OSError, e: # Linux does this
829 self.flag_eof = True
829 self.flag_eof = True
830 raise EOF ('End Of File (EOF) in read_nonblocking(). Exception style platform.')
830 raise EOF ('End Of File (EOF) in read_nonblocking(). Exception style platform.')
831 if s == '': # BSD style
831 if s == b'': # BSD style
832 self.flag_eof = True
832 self.flag_eof = True
833 raise EOF ('End Of File (EOF) in read_nonblocking(). Empty string style platform.')
833 raise EOF ('End Of File (EOF) in read_nonblocking(). Empty string style platform.')
834
834
@@ -936,12 +936,14 b' class spawn (object):'
936 for s in sequence:
936 for s in sequence:
937 self.write (s)
937 self.write (s)
938
938
939 def send(self, s):
939 def send(self, s, encoding='utf-8'):
940
940
941 """This sends a string to the child process. This returns the number of
941 """This sends a string to the child process. This returns the number of
942 bytes written. If a log file was set then the data is also written to
942 bytes written. If a log file was set then the data is also written to
943 the log. """
943 the log. """
944
944
945 if isinstance(s, unicode):
946 s = s.encode(encoding)
945 time.sleep(self.delaybeforesend)
947 time.sleep(self.delaybeforesend)
946 if self.logfile is not None:
948 if self.logfile is not None:
947 self.logfile.write (s)
949 self.logfile.write (s)
@@ -1208,7 +1210,7 b' class spawn (object):'
1208
1210
1209 if patterns is None:
1211 if patterns is None:
1210 return []
1212 return []
1211 if type(patterns) is not types.ListType:
1213 if not isinstance(patterns, list):
1212 patterns = [patterns]
1214 patterns = [patterns]
1213
1215
1214 compile_flags = re.DOTALL # Allow dot to match \n
1216 compile_flags = re.DOTALL # Allow dot to match \n
@@ -1216,7 +1218,7 b' class spawn (object):'
1216 compile_flags = compile_flags | re.IGNORECASE
1218 compile_flags = compile_flags | re.IGNORECASE
1217 compiled_pattern_list = []
1219 compiled_pattern_list = []
1218 for p in patterns:
1220 for p in patterns:
1219 if type(p) in types.StringTypes:
1221 if isinstance(p, basestring):
1220 compiled_pattern_list.append(re.compile(p, compile_flags))
1222 compiled_pattern_list.append(re.compile(p, compile_flags))
1221 elif p is EOF:
1223 elif p is EOF:
1222 compiled_pattern_list.append(EOF)
1224 compiled_pattern_list.append(EOF)
@@ -1337,7 +1339,7 b' class spawn (object):'
1337 This method is also useful when you don't want to have to worry about
1339 This method is also useful when you don't want to have to worry about
1338 escaping regular expression characters that you want to match."""
1340 escaping regular expression characters that you want to match."""
1339
1341
1340 if type(pattern_list) in types.StringTypes or pattern_list in (TIMEOUT, EOF):
1342 if isinstance(pattern_list, basestring) or pattern_list in (TIMEOUT, EOF):
1341 pattern_list = [pattern_list]
1343 pattern_list = [pattern_list]
1342 return self.expect_loop(searcher_string(pattern_list), timeout, searchwindowsize)
1344 return self.expect_loop(searcher_string(pattern_list), timeout, searchwindowsize)
1343
1345
@@ -1371,7 +1373,7 b' class spawn (object):'
1371 self.match_index = index
1373 self.match_index = index
1372 return self.match_index
1374 return self.match_index
1373 # No match at this point
1375 # No match at this point
1374 if timeout < 0 and timeout is not None:
1376 if timeout is not None and timeout < 0:
1375 raise TIMEOUT ('Timeout exceeded in expect_any().')
1377 raise TIMEOUT ('Timeout exceeded in expect_any().')
1376 # Still have time left, so read more data
1378 # Still have time left, so read more data
1377 c = self.read_nonblocking (self.maxread, timeout)
1379 c = self.read_nonblocking (self.maxread, timeout)
@@ -1381,7 +1383,7 b' class spawn (object):'
1381 if timeout is not None:
1383 if timeout is not None:
1382 timeout = end_time - time.time()
1384 timeout = end_time - time.time()
1383 except EOF, e:
1385 except EOF, e:
1384 self.buffer = ''
1386 self.buffer = b''
1385 self.before = incoming
1387 self.before = incoming
1386 self.after = EOF
1388 self.after = EOF
1387 index = searcher.eof_index
1389 index = searcher.eof_index
@@ -1484,7 +1486,7 b' class spawn (object):'
1484 # Flush the buffer.
1486 # Flush the buffer.
1485 self.stdout.write (self.buffer)
1487 self.stdout.write (self.buffer)
1486 self.stdout.flush()
1488 self.stdout.flush()
1487 self.buffer = ''
1489 self.buffer = b''
1488 mode = tty.tcgetattr(self.STDIN_FILENO)
1490 mode = tty.tcgetattr(self.STDIN_FILENO)
1489 tty.setraw(self.STDIN_FILENO)
1491 tty.setraw(self.STDIN_FILENO)
1490 try:
1492 try:
@@ -1700,7 +1702,7 b' class searcher_re (object):'
1700 self.eof_index = -1
1702 self.eof_index = -1
1701 self.timeout_index = -1
1703 self.timeout_index = -1
1702 self._searches = []
1704 self._searches = []
1703 for n, s in zip(range(len(patterns)), patterns):
1705 for n, s in enumerate(patterns):
1704 if s is EOF:
1706 if s is EOF:
1705 self.eof_index = n
1707 self.eof_index = n
1706 continue
1708 continue
@@ -1721,7 +1723,7 b' class searcher_re (object):'
1721 if self.timeout_index >= 0:
1723 if self.timeout_index >= 0:
1722 ss.append ((self.timeout_index,' %d: TIMEOUT' % self.timeout_index))
1724 ss.append ((self.timeout_index,' %d: TIMEOUT' % self.timeout_index))
1723 ss.sort()
1725 ss.sort()
1724 ss = zip(*ss)[1]
1726 ss = [a[1] for a in ss]
1725 return '\n'.join(ss)
1727 return '\n'.join(ss)
1726
1728
1727 def search(self, buffer, freshlen, searchwindowsize=None):
1729 def search(self, buffer, freshlen, searchwindowsize=None):
General Comments 0
You need to be logged in to leave comments. Login now