MCPcopy Index your code
hub / github.com/RustPython/RustPython / readexactly

Method readexactly

Lib/asyncio/streams.py:739–778  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

737 return data
738
739 async def readexactly(self, n):
740 """Read exactly `n` bytes.
741
742 Raise an IncompleteReadError if EOF is reached before `n` bytes can be
743 read. The IncompleteReadError.partial attribute of the exception will
744 contain the partial read bytes.
745
746 if n is zero, return empty bytes object.
747
748 Returned value is not limited with limit, configured at stream
749 creation.
750
751 If stream was paused, this function will automatically resume it if
752 needed.
753 """
754 if n < 0:
755 raise ValueError('readexactly size can not be less than zero')
756
757 if self._exception is not None:
758 raise self._exception
759
760 if n == 0:
761 return b''
762
763 while len(self._buffer) < n:
764 if self._eof:
765 incomplete = bytes(self._buffer)
766 self._buffer.clear()
767 raise exceptions.IncompleteReadError(incomplete, n)
768
769 await self._wait_for_data('readexactly')
770
771 if len(self._buffer) == n:
772 data = bytes(self._buffer)
773 self._buffer.clear()
774 else:
775 data = bytes(memoryview(self._buffer)[:n])
776 del self._buffer[:n]
777 self._maybe_resume_transport()
778 return data
779
780 def __aiter__(self):
781 return self

Callers 9

test_readexactlyMethod · 0.95
test_readexactly_eofMethod · 0.95
handle_clientMethod · 0.80
clientMethod · 0.80
client_sockMethod · 0.80
on_server_clientMethod · 0.80

Calls 4

_wait_for_dataMethod · 0.95
lenFunction · 0.85
clearMethod · 0.45

Tested by 9

test_readexactlyMethod · 0.76
test_readexactly_eofMethod · 0.76
handle_clientMethod · 0.64
clientMethod · 0.64
client_sockMethod · 0.64
on_server_clientMethod · 0.64