Read until a given string is encountered or until timeout. When no match is found, return whatever is available instead, possibly the empty string. Raise EOFError if the connection is closed and no cooked data is available.
(self, match, timeout=None)
| 295 | self.sock.sendall(buffer) |
| 296 | |
| 297 | def read_until(self, match, timeout=None): |
| 298 | """Read until a given string is encountered or until timeout. |
| 299 | |
| 300 | When no match is found, return whatever is available instead, |
| 301 | possibly the empty string. Raise EOFError if the connection |
| 302 | is closed and no cooked data is available. |
| 303 | |
| 304 | """ |
| 305 | n = len(match) |
| 306 | self.process_rawq() |
| 307 | i = self.cookedq.find(match) |
| 308 | if i >= 0: |
| 309 | i = i+n |
| 310 | buf = self.cookedq[:i] |
| 311 | self.cookedq = self.cookedq[i:] |
| 312 | return buf |
| 313 | if timeout is not None: |
| 314 | deadline = _time() + timeout |
| 315 | with _TelnetSelector() as selector: |
| 316 | selector.register(self, selectors.EVENT_READ) |
| 317 | while not self.eof: |
| 318 | if selector.select(timeout): |
| 319 | i = max(0, len(self.cookedq)-n) |
| 320 | self.fill_rawq() |
| 321 | self.process_rawq() |
| 322 | i = self.cookedq.find(match, i) |
| 323 | if i >= 0: |
| 324 | i = i+n |
| 325 | buf = self.cookedq[:i] |
| 326 | self.cookedq = self.cookedq[i:] |
| 327 | return buf |
| 328 | if timeout is not None: |
| 329 | timeout = deadline - _time() |
| 330 | if timeout < 0: |
| 331 | break |
| 332 | return self.read_very_lazy() |
| 333 | |
| 334 | def read_all(self): |
| 335 | """Read all data until EOF; block until connection closed.""" |
nothing calls this directly
no test coverage detected