Read exactly `n` bytes. Raise an IncompleteReadError if EOF is reached before `n` bytes can be read. The IncompleteReadError.partial attribute of the exception will contain the partial read bytes. if n is zero, return empty bytes object. Returned value is n
(self, n)
| 729 | return data |
| 730 | |
| 731 | async def readexactly(self, n): |
| 732 | """Read exactly `n` bytes. |
| 733 | |
| 734 | Raise an IncompleteReadError if EOF is reached before `n` bytes can be |
| 735 | read. The IncompleteReadError.partial attribute of the exception will |
| 736 | contain the partial read bytes. |
| 737 | |
| 738 | if n is zero, return empty bytes object. |
| 739 | |
| 740 | Returned value is not limited with limit, configured at stream |
| 741 | creation. |
| 742 | |
| 743 | If stream was paused, this function will automatically resume it if |
| 744 | needed. |
| 745 | """ |
| 746 | if n < 0: |
| 747 | raise ValueError('readexactly size can not be less than zero') |
| 748 | |
| 749 | if self._exception is not None: |
| 750 | raise self._exception |
| 751 | |
| 752 | if n == 0: |
| 753 | return b'' |
| 754 | |
| 755 | while len(self._buffer) < n: |
| 756 | if self._eof: |
| 757 | incomplete = self._buffer.take_bytes() |
| 758 | raise exceptions.IncompleteReadError(incomplete, n) |
| 759 | |
| 760 | await self._wait_for_data('readexactly') |
| 761 | |
| 762 | data = self._buffer.take_bytes(n) |
| 763 | self._maybe_resume_transport() |
| 764 | return data |
| 765 | |
| 766 | def __aiter__(self): |
| 767 | return self |