MCPcopy Index your code
hub / github.com/python/cpython / readexactly

Method readexactly

Lib/asyncio/streams.py:731–764  ·  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

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

Callers 10

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

Calls 3

_wait_for_dataMethod · 0.95
take_bytesMethod · 0.80

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