MCPcopy Create free account
hub / github.com/python-websockets/websockets / read_to_eof

Method read_to_eof

src/websockets/streams.py:77–97  ·  view source on GitHub ↗

Read all bytes from the stream. This is a generator-based coroutine. Args: m: Maximum number bytes to read; this is a security limit. Raises: RuntimeError: If the stream ends in more than ``m`` bytes.

(self, m: int)

Source from the content-addressed store, hash-verified

75 return r
76
77 def read_to_eof(self, m: int) -> Generator[None, None, bytearray]:
78 """
79 Read all bytes from the stream.
80
81 This is a generator-based coroutine.
82
83 Args:
84 m: Maximum number bytes to read; this is a security limit.
85
86 Raises:
87 RuntimeError: If the stream ends in more than ``m`` bytes.
88
89 """
90 while not self.eof:
91 p = len(self.buffer)
92 if p > m:
93 raise RuntimeError(f"read {p} bytes, expected no more than {m} bytes")
94 yield
95 r = self.buffer[:]
96 del self.buffer[:]
97 return r
98
99 def at_eof(self) -> Generator[None, None, bool]:
100 """

Callers 4

test_read_to_eofMethod · 0.80
test_discardMethod · 0.80

Calls

no outgoing calls

Tested by 4

test_read_to_eofMethod · 0.64
test_discardMethod · 0.64