auto 5ˆÍÌ „DÓ¿Ë¿Ï?÷5from io import StringIO, BytesIO import codecs import os import sys import re import errno from .exceptions import ExceptionPexpect, EOF, TIMEOUT from .expect import Expecter, searcher_string, searcher_re PY3 = (sys.version_info[0] >= 3) text_type = str if PY3 else unicode class _NullCoder(object): """Pass bytes through unchanged.""" @staticmethod def encode(b, final=False): return b @staticmethod def decode(b, final=False): return b class SpawnBase(object): """A base class providing the backwards-compatible spawn API for Pexpect. This should not be instantiated directly: use :class:`pexpect.spawn` or :class:`pexpect.fdpexpect.fdspawn`. """ encoding = None pid = None flag_eof = False def __init__(self, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, encoding=None, codec_errors='strict'): self.stdin = sys.stdin self.stdout = sys.stdout self.stderr = sys.stderr self.searcher = None self.ignorecase = False self.before = None self.after = None self.match = None self.match_index = None self.terminated = True self.exitstatus = None self.signalstatus = None # status returned by os.waitpid self.status = None # the child file descriptor is initially closed self.child_fd = -1 self.timeout = timeout self.delimiter = EOF self.logfile = logfile # input from child (read_nonblocking) self.logfile_read = None # output to send (send, sendline) self.logfile_send = None # max bytes to read at one time into buffer self.maxread = maxread # Data before searchwindowsize point is preserved, but not searched. self.searchwindowsize = searchwindowsize # Delay used before sending data to child. Time in seconds. # Set this to None to skip the time.sleep() call completely. self.delaybeforesend = 0.05 # Used by close() to give kernel time to update process status. # Time in seconds. self.delayafterclose = 0.1 # Used by terminate() to give kernel time to update process status. # Time in seconds. self.delayafterterminate = 0.1 # Delay in seconds to sleep after each call to read_nonblocking(). # Set this to None to skip the time.sleep() call completely: that # would restore the behavior from pexpect-2.0 (for performance # reasons or because you don't want to release Python's global # interpreter lock). self.delayafterread = 0.0001 self.softspace = False self.name = '<' + repr(self) + '>' self.closed = True # Unicode interface self.encoding = encoding self.codec_errors = codec_errors if encoding is None: # bytes mode (accepts some unicode for backwards compatibility) self._encoder = self._decoder = _NullCoder() self.string_type = bytes self.buffer_type = BytesIO self.crlf = b'\r\n' if PY3: self.allowed_string_types = (bytes, str) self.linesep = os.linesep.encode('ascii') def write_to_stdout(b): try: return sys.stdout.buffer.write(b) except AttributeError: # If stdout has been replaced, it may not have .buffer return sys.stdout.write(b.decode('ascii', 'replace')) self.write_to_stdout = write_to_stdout else: self.allowed_string_types = (basestring,) # analysis:ignore self.linesep = os.linesep self.write_to_stdout = sys.stdout.write else: # unicode mode self._encoder = codecs.getincrementalencoder(encoding)(codec_errors) self._decoder = codecs.getincrementaldecoder(encoding)(codec_error