waituntil() reads until `stop` bytes sequence.
(self, stop, limit=None)
| 430 | self._writer.send((yield)) |
| 431 | |
| 432 | def waituntil(self, stop, limit=None): |
| 433 | """waituntil() reads until `stop` bytes sequence.""" |
| 434 | assert isinstance(stop, bytes) and stop, \ |
| 435 | 'bytes is required: {!r}'.format(stop) |
| 436 | |
| 437 | stop_len = len(stop) |
| 438 | |
| 439 | while True: |
| 440 | if self._helper.exception: |
| 441 | raise self._helper.exception |
| 442 | |
| 443 | pos = self._data.find(stop) |
| 444 | if pos >= 0: |
| 445 | size = pos + stop_len |
| 446 | if limit is not None and size > limit: |
| 447 | raise errors.LineLimitExceededParserError( |
| 448 | 'Line is too long. %s' % bytes(self._data), limit) |
| 449 | |
| 450 | return self._data[:size] |
| 451 | else: |
| 452 | if limit is not None and len(self._data) > limit: |
| 453 | raise errors.LineLimitExceededParserError( |
| 454 | 'Line is too long. %s' % bytes(self._data), limit) |
| 455 | |
| 456 | self._writer.send((yield)) |
| 457 | |
| 458 | def skip(self, size): |
| 459 | """skip() skips specified amount of bytes.""" |