示例#1
0
 def expect(self, patt, mtype=EXACT, callback=None, timeout=None):
     timeout = timeout or self.default_timeout
     searchlist = self._get_search_list(patt, mtype, callback)
     if not searchlist:
         raise ExpectError("Empty expect search.")
     time.iotimeout(self._fill_buf, timeout=timeout)
     matchbuf = bytes()
     while 1:
         c = self._inbuf.read(1)
         if not c:
             time.iotimeout(self._fill_buf, timeout=timeout)
             continue
         matchbuf += c
         for index, (so, cb) in enumerate(searchlist):
             mo = so.search(matchbuf)
             if mo:
                 mo.string = mo.string.decode("utf-8")
                 if cb is not None:
                     cb(mo)
                 return mo, index
示例#2
0
 def readline(self, timeout=None):
     timeout = timeout or self.default_timeout
     if self._inbuf:
         bd = self._inbuf.read()
         i = bd.find(b'\n')
         if i >= 0:
             line = bd[:i + 1]
             self._inbuf.write(bd[i + 1:])
             return line
         else:
             return bd + self._fo.readline()
     else:
         return time.iotimeout(self._fo.readline, timeout=timeout)
示例#3
0
 def read(self, amt=-1, timeout=None):
     timeout = timeout or self.default_timeout
     if len(self._inbuf) > 0:
         return self._inbuf.read(amt)
     return time.iotimeout(partial(self._fo.read, amt), timeout=timeout)
示例#4
0
 def send(self, text, timeout=None, encoding="utf-8"):
     timeout = timeout or self.default_timeout
     return time.iotimeout(partial(self._fo.write, text.encode(encoding)),
                           timeout=timeout)
示例#5
0
 def _read(self):
     inp = time.iotimeout(partial(self._fo.read, 4096), timeout=self._timeout)
     self._fsm.process_string(inp)