parameters: (self, buffer, freshlen, searchwindowsize=None)
return_statement: return best_index
docstring: This searches 'buffer' for the first occurrence of one of the search
          strings.  'freshlen' must indicate the number of bytes at the end of
          'buffer' which have not been searched before. It helps to avoid
          searching the same, possibly big, buffer over and over again.
  
          See class spawn for the 'searchwindowsize' argument.
  
          If there is a match this returns the index of that string, and sets
          'start', 'end' and 'match'. Otherwise, this returns -1.
docstring_summary: This searches 'buffer' for the first occurrence of one of the search
          strings.  'freshlen' must indicate the number of bytes at the end of
          'buffer' which have not been searched before. It helps to avoid
          searching the same, possibly big, buffer over and over again.
docstring_tokens: This searches buffer for the first occurrence of one of the search strings . freshlen must indicate the number of bytes at the end of buffer which have not been searched before . It helps to avoid searching the same possibly big buffer over and over again .
function: def search(self, buffer, freshlen, searchwindowsize=None):
          '''This searches 'buffer' for the first occurrence of one of the search
          strings.  'freshlen' must indicate the number of bytes at the end of
          'buffer' which have not been searched before. It helps to avoid
          searching the same, possibly big, buffer over and over again.
  
          See class spawn for the 'searchwindowsize' argument.
  
          If there is a match this returns the index of that string, and sets
          'start', 'end' and 'match'. Otherwise, this returns -1. '''
  
          first_match = None
  
          # 'freshlen' helps a lot here. Further optimizations could
          # possibly include:
          #
          # using something like the Boyer-Moore Fast String Searching
          # Algorithm; pre-compiling the search through a list of
          # strings into something that can scan the input once to
          # search for all N strings; realize that if we search for
          # ['bar', 'baz'] and the input is '...foo' we need not bother
          # rescanning until we've read three more bytes.
          #
          # Sadly, I don't know enough about this interesting topic. /grahn
  
          for index, s in self._strings:
              if searchwindowsize is None:
                  # the match, if any, can only be in the fresh data,
                  # or at the very end of the old data
                  offset = -(freshlen + len(s))
              else:
                  # better obey searchwindowsize
                  offset = -searchwindowsize
              n = buffer.find(s, offset)
              if n >= 0 and (first_match is None or n < first_match):
                  first_match = n
                  best_index, best_match = index, s
          if first_match is None:
              return -1
          self.match = best_match
          self.start = first_match
          self.end = self.start + len(self.match)
          return best_index
function_tokens: def search ( self , buffer , freshlen , searchwindowsize = None ) : first_match = None # 'freshlen' helps a lot here. Further optimizations could # possibly include: # # using something like the Boyer-Moore Fast String Searching # Algorithm; pre-compiling the search through a list of # strings into something that can scan the input once to # search for all N strings; realize that if we search for # ['bar', 'baz'] and the input is '...foo' we need not bother # rescanning until we've read three more bytes. # # Sadly, I don't know enough about this interesting topic. /grahn for index , s in self . _strings : if searchwindowsize is None : # the match, if any, can only be in the fresh data, # or at the very end of the old data offset = - ( freshlen + len ( s ) ) else : # better obey searchwindowsize offset = - searchwindowsize n = buffer . find ( s , offset ) if n >= 0 and ( first_match is None or n < first_match ) : first_match = n best_index , best_match = index , s if first_match is None : return - 1 self . match = best_match self . start = first_match self . end = self . start + len ( self . match ) return best_index