| 389 | self._writer.send((yield)) |
| 390 | |
| 391 | def readuntil(self, stop, limit=None): |
| 392 | assert isinstance(stop, bytes) and stop, \ |
| 393 | 'bytes is required: {!r}'.format(stop) |
| 394 | |
| 395 | stop_len = len(stop) |
| 396 | |
| 397 | while True: |
| 398 | if self._helper.exception: |
| 399 | raise self._helper.exception |
| 400 | |
| 401 | pos = self._data.find(stop) |
| 402 | if pos >= 0: |
| 403 | end = pos + stop_len |
| 404 | size = end |
| 405 | if limit is not None and size > limit: |
| 406 | raise errors.LineLimitExceededParserError( |
| 407 | 'Line is too long.', limit) |
| 408 | |
| 409 | data = self._data[:size] |
| 410 | del self._data[:size] |
| 411 | return data |
| 412 | else: |
| 413 | if limit is not None and len(self._data) > limit: |
| 414 | raise errors.LineLimitExceededParserError( |
| 415 | 'Line is too long.', limit) |
| 416 | |
| 417 | self._writer.send((yield)) |
| 418 | |
| 419 | def wait(self, size): |
| 420 | """wait() waits for specified amount of bytes |