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