Blocking expect
(self, timeout=-1)
| 151 | spawn.match_index = None |
| 152 | |
| 153 | def expect_loop(self, timeout=-1): |
| 154 | """Blocking expect""" |
| 155 | spawn = self.spawn |
| 156 | |
| 157 | if timeout is not None: |
| 158 | end_time = time.time() + timeout |
| 159 | |
| 160 | try: |
| 161 | idx = self.existing_data() |
| 162 | if idx is not None: |
| 163 | return idx |
| 164 | while True: |
| 165 | # No match at this point |
| 166 | if (timeout is not None) and (timeout < 0): |
| 167 | return self.timeout() |
| 168 | # Still have time left, so read more data |
| 169 | incoming = spawn.read_nonblocking(spawn.maxread, timeout) |
| 170 | if self.spawn.delayafterread is not None: |
| 171 | time.sleep(self.spawn.delayafterread) |
| 172 | idx = self.new_data(incoming) |
| 173 | # Keep reading until exception or return. |
| 174 | if idx is not None: |
| 175 | return idx |
| 176 | if timeout is not None: |
| 177 | timeout = end_time - time.time() |
| 178 | except EOF as e: |
| 179 | return self.eof(e) |
| 180 | except TIMEOUT as e: |
| 181 | return self.timeout(e) |
| 182 | except: |
| 183 | self.errored() |
| 184 | raise |
| 185 | |
| 186 | |
| 187 | class searcher_string(object): |
no test coverage detected