Read chunk of data from the stream until newline (b'\n') is found. On success, return chunk that ends with newline. If only partial line can be read due to EOF, return incomplete line without terminating newline. When EOF was reached while no bytes read, empty bytes
(self)
| 539 | self._waiter = None |
| 540 | |
| 541 | async def readline(self): |
| 542 | """Read chunk of data from the stream until newline (b'\n') is found. |
| 543 | |
| 544 | On success, return chunk that ends with newline. If only partial |
| 545 | line can be read due to EOF, return incomplete line without |
| 546 | terminating newline. When EOF was reached while no bytes read, empty |
| 547 | bytes object is returned. |
| 548 | |
| 549 | If limit is reached, ValueError will be raised. In that case, if |
| 550 | newline was found, complete line including newline will be removed |
| 551 | from internal buffer. Else, internal buffer will be cleared. Limit is |
| 552 | compared against part of the line without newline. |
| 553 | |
| 554 | If stream was paused, this function will automatically resume it if |
| 555 | needed. |
| 556 | """ |
| 557 | sep = b'\n' |
| 558 | seplen = len(sep) |
| 559 | try: |
| 560 | line = await self.readuntil(sep) |
| 561 | except exceptions.IncompleteReadError as e: |
| 562 | return e.partial |
| 563 | except exceptions.LimitOverrunError as e: |
| 564 | if self._buffer.startswith(sep, e.consumed): |
| 565 | del self._buffer[:e.consumed + seplen] |
| 566 | else: |
| 567 | self._buffer.clear() |
| 568 | self._maybe_resume_transport() |
| 569 | raise ValueError(e.args[0]) |
| 570 | return line |
| 571 | |
| 572 | async def readuntil(self, separator=b'\n'): |
| 573 | """Read data from the stream until ``separator`` is found. |