class_docstr: 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`.
docstr: This seeks through the stream until a pattern is matched. The
  pattern is overloaded and may take several types. The pattern can be a
  StringType, EOF, a compiled re, or a list of any of those types.
  Strings will be compiled to re types. This returns the index into the
  pattern list. If the pattern was not a list this returns index 0 on a
  successful match. This may raise exceptions for EOF or TIMEOUT. To
  avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to the pattern
  list. That will cause expect to match an EOF or TIMEOUT condition
  instead of raising an exception.
  
  If you pass a list of patterns and more than one matches, the first
  match in the stream is chosen. If more than one pattern matches at that
  point, the leftmost in the pattern list is chosen. For example::
  
      # the input is 'foobar'
      index = p.expect(['bar', 'foo', 'foobar'])
      # returns 1('foo') even though 'foobar' is a "better" match
  
  Please note, however, that buffering can affect this behavior, since
  input arrives in unpredictable chunks. For example::
  
      # the input is 'foobar'
      index = p.expect(['foobar', 'foo'])
      # returns 0('foobar') if all input is available at once,
      # but returns 1('foo') if parts of the final 'bar' arrive late
  
  When a match is found for the given pattern, the class instance
  attribute *match* becomes an re.MatchObject result.  Should an EOF
  or TIMEOUT pattern match, then the match attribute will be an instance
  of that exception class.  The pairing before and after class
  instance attributes are views of the data preceding and following
  the matching pattern.  On general exception, class attribute
  *before* is all data received up to the exception, while *match* and
  *after* attributes are value None.
  
  When the keyword argument timeout is -1 (default), then TIMEOUT will
  raise after the default value specified by the class timeout
  attribute. When None, TIMEOUT will not be raised and may block
  indefinitely until match.
  
  When the keyword argument searchwindowsize is -1 (default), then the
  value specified by the class maxread attribute is used.
  
  A list entry may be EOF or TIMEOUT instead of a string. This will
  catch these exceptions and return the index of the list entry instead
  of raising the exception. The attribute 'after' will be set to the
  exception type. The attribute 'match' will be None. This allows you to
  write code like this::
  
          index = p.expect(['good', 'bad', pexpect.EOF, pexpect.TIMEOUT])
          if index == 0:
              do_something()
          elif index == 1:
              do_something_else()
          elif index == 2:
              do_some_other_thing()
          elif index == 3:
              do_something_completely_different()
  
  instead of code like this::
  
          try:
              index = p.expect(['good', 'bad'])
              if index == 0:
                  do_something()
              elif index == 1:
                  do_something_else()
          except EOF:
              do_some_other_thing()
          except TIMEOUT:
              do_something_completely_different()
  
  These two forms are equivalent. It all depends on what you want. You
  can also just expect the EOF if you are waiting for all output of a
  child to finish. For example::
  
          p = pexpect.spawn('/bin/ls')
          p.expect(pexpect.EOF)
          print p.before
  
  If you are trying to optimize for speed then see expect_list().
  
  On Python 3.4, or Python 3.3 with asyncio installed, passing
  ``async_=True``  will make this return an :mod:`asyncio` coroutine,
  which you can yield from to get the same result that this method would
  normally give directly. So, inside a coroutine, you can replace this code::
  
      index = p.expect(patterns)
  
  With this non-blocking form::
  
      index = yield from p.expect(patterns, async_=True)
docstr_tok: ["This","seeks","through","the","stream","until","a","pattern","is","matched",".","The","pattern","is","overloaded","and","may","take","several","types",".","The","pattern","can","be","a","StringType",",","EOF",",","a","compiled","re",",","or","a","list","of","any","of","those","types",".","Strings","will","be","compiled","to","re","types",".","This","returns","the","index","into","the","pattern","list",".","If","the","pattern","was","not","a","list","this","returns","index","0","on","a","successful","match",".","This","may","raise","exceptions","for","EOF","or","TIMEOUT",".","To","avoid","the","EOF","or","TIMEOUT","exceptions","add","EOF","or","TIMEOUT","to","the","pattern","list",".","That","will","cause","expect","to","match","an","EOF","or","TIMEOUT","condition","instead","of","raising","an","exception",".","If","you","pass","a","list","of","patterns","and","more","than","one","matches",",","the","first","match","in","the","stream","is","chosen",".","If","more","than","one","pattern","matches","at","that","point",",","the","leftmost","in","the","pattern","list","is","chosen",".","For","example",":",":","#","the","input","is","'foobar'","index","=","p.expect","(","[","'bar","'",",","'foo","'",",","'foobar","'","]",")","#","returns","1","(","'foo","'",")","even","though","'foobar","'","is","a","``","better","''","match","Please","note",",","however",",","that","buffering","can","affect","this","behavior",",","since","input","arrives","in","unpredictable","chunks",".","For","example",":",":","#","the","input","is","'foobar'","index","=","p.expect","(","[","'foobar","'",",","'foo","'","]",")","#","returns","0","(","'foobar","'",")","if","all","input","is","available","at","once",",","#","but","returns","1","(","'foo","'",")","if","parts","of","the","final","'bar","'","arrive","late","When","a","match","is","found","for","the","given","pattern",",","the","class","instance","attribute","*","match","*","becomes","an","re.MatchObject","result",".","Should","an","EOF","or","TIMEOUT","pattern","match",",","then","the","match","attribute","will","be","an","instance","of","that","exception","class",".","The","pairing","before","and","after","class","instance","attributes","are","views","of","the","data","preceding","and","following","the","matching","pattern",".","On","general","exception",",","class","attribute","*","before","*","is","all","data","received","up","to","the","exception",",","while","*","match","*","and","*","after","*","attributes","are","value","None",".","When","the","keyword","argument","timeout","is","-1","(","default",")",",","then","TIMEOUT","will","raise","after","the","default","value","specified","by","the","class","timeout","attribute",".","When","None",",","TIMEOUT","will","not","be","raised","and","may","block","indefinitely","until","match",".","When","the","keyword","argument","searchwindowsize","is","-1","(","default",")",",","then","the","value","specified","by","the","class","maxread","attribute","is","used",".","A","list","entry","may","be","EOF","or","TIMEOUT","instead","of","a","string",".","This","will","catch","these","exceptions","and","return","the","index","of","the","list","entry","instead","of","raising","the","exception",".","The","attribute","'after","'","will","be","set","to","the","exception","type",".","The","attribute","'match","'","will","be","None",".","This","allows","you","to","write","code","like","this",":",":","index","=","p.expect","(","[","'good","'",",","'bad","'",",","pexpect.EOF",",","pexpect.TIMEOUT","]",")","if","index","==","0",":","do_something","(",")","elif","index","==","1",":","do_something_else","(",")","elif","index","==","2",":","do_some_other_thing","(",")","elif","index","==","3",":","do_something_completely_different","(",")","instead","of","code","like","this",":",":","try",":","index","=","p.expect","(","[","'good","'",",","'bad","'","]",")","if","index","==","0",":","do_something","(",")","elif","index","==","1",":","do_something_else","(",")","except","EOF",":","do_some_other_thing","(",")","except","TIMEOUT",":","do_something_completely_different","(",")","These","two","forms","are","equivalent",".","It","all","depends","on","what","you","want",".","You","can","also","just","expect","the","EOF","if","you","are","waiting","for","all","output","of","a","child","to","finish",".","For","example",":",":","p","=","pexpect.spawn","(","'\/bin\/ls","'",")","p.expect","(","pexpect.EOF",")","print","p.before","If","you","are","trying","to","optimize","for","speed","then","see","expect_list","(",")",".","On","Python","3.4",",","or","Python","3.3","with","asyncio","installed",",","passing","``","async_=True","``","will","make","this","return","an",":","mod",":","`","asyncio","`","coroutine",",","which","you","can","yield","from","to","get","the","same","result","that","this","method","would","normally","give","directly",".","So",",","inside","a","coroutine",",","you","can","replace","this","code",":",":","index","=","p.expect","(","patterns",")","With","this","non-blocking","form",":",":","index","=","yield","from","p.expect","(","patterns",",","async_=True",")"]
code: def expect(
      self, pattern, timeout=-1, searchwindowsize=-1, async_=False, **kw
  ):
      """This seeks through the stream until a pattern is matched. The
      pattern is overloaded and may take several types. The pattern can be a
      StringType, EOF, a compiled re, or a list of any of those types.
      Strings will be compiled to re types. This returns the index into the
      pattern list. If the pattern was not a list this returns index 0 on a
      successful match. This may raise exceptions for EOF or TIMEOUT. To
      avoid the EOF or TIMEOUT exceptions add EOF or TIMEOUT to the pattern
      list. That will cause expect to match an EOF or TIMEOUT condition
      instead of raising an exception.
  
      If you pass a list of patterns and more than one matches, the first
      match in the stream is chosen. If more than one pattern matches at that
      point, the leftmost in the pattern list is chosen. For example::
  
          # the input is 'foobar'
          index = p.expect(['bar', 'foo', 'foobar'])
          # returns 1('foo') even though 'foobar' is a "better" match
  
      Please note, however, that buffering can affect this behavior, since
      input arrives in unpredictable chunks. For example::
  
          # the input is 'foobar'
          index = p.expect(['foobar', 'foo'])
          # returns 0('foobar') if all input is available at once,
          # but returns 1('foo') if parts of the final 'bar' arrive late
  
      When a match is found for the given pattern, the class instance
      attribute *match* becomes an re.MatchObject result.  Should an EOF
      or TIMEOUT pattern match, then the match attribute will be an instance
      of that exception class.  The pairing before and after class
      instance attributes are views of the data preceding and following
      the matching pattern.  On general exception, class attribute
      *before* is all data received up to the exception, while *match* and
      *after* attributes are value None.
  
      When the keyword argument timeout is -1 (default), then TIMEOUT will
      raise after the default value specified by the class timeout
      attribute. When None, TIMEOUT will not be raised and may block
      indefinitely until match.
  
      When the keyword argument searchwindowsize is -1 (default), then the
      value specified by the class maxread attribute is used.
  
      A list entry may be EOF or TIMEOUT instead of a string. This will
      catch these exceptions and return the index of the list entry instead
      of raising the exception. The attribute 'after' will be set to the
      exception type. The attribute 'match' will be None. This allows you to
      write code like this::
  
              index = p.expect(['good', 'bad', pexpect.EOF, pexpect.TIMEOUT])
              if index == 0:
                  do_something()
              elif index == 1:
                  do_something_else()
              elif index == 2:
                  do_some_other_thing()
              elif index == 3:
                  do_something_completely_different()
  
      instead of code like this::
  
              try:
                  index = p.expect(['good', 'bad'])
                  if index == 0:
                      do_something()
                  elif index == 1:
                      do_something_else()
              except EOF:
                  do_some_other_thing()
              except TIMEOUT:
                  do_something_completely_different()
  
      These two forms are equivalent. It all depends on what you want. You
      can also just expect the EOF if you are waiting for all output of a
      child to finish. For example::
  
              p = pexpect.spawn('/bin/ls')
              p.expect(pexpect.EOF)
              print p.before
  
      If you are trying to optimize for speed then see expect_list().
  
      On Python 3.4, or Python 3.3 with asyncio installed, passing
      ``async_=True``  will make this return an :mod:`asyncio` coroutine,
      which you can yield from to get the same result that this method would
      normally give directly. So, inside a coroutine, you can replace this code::
  
          index = p.expect(patterns)
  
      With this non-blocking form::
  
          index = yield from p.expect(patterns, async_=True)
      """
      if "async" in kw:
          async_ = kw.pop("async")
      if kw:
          raise TypeError("Unknown keyword arguments: {}".format(kw))
  
      compiled_pattern_list = self.compile_pattern_list(pattern)
      return self.expect_list(
          compiled_pattern_list, timeout, searchwindowsize, async_
      )
  
imports: from 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
label_desc: Use image node_id 11 for calling the SpawnBase obj's underlying member method code with example usage: obj.expect(pattern, timeout, searchwindowsize, async_) and returns: self