WebSocketReader subclass that allows for patching parse_frame.
| 24 | |
| 25 | |
| 26 | class PatchableWebSocketReader(WebSocketReader): |
| 27 | """WebSocketReader subclass that allows for patching parse_frame.""" |
| 28 | |
| 29 | def parse_frame( |
| 30 | self, data: bytes |
| 31 | ) -> list[tuple[bool, int, bytes | bytearray, int]]: |
| 32 | # This method is overridden to allow for patching in tests. |
| 33 | frames: list[tuple[bool, int, bytes | bytearray, int]] = [] |
| 34 | |
| 35 | def _handle_frame( |
| 36 | fin: bool, |
| 37 | opcode: int, |
| 38 | payload: bytes | bytearray, |
| 39 | compressed: int, |
| 40 | ) -> None: |
| 41 | # This method is overridden to allow for patching in tests. |
| 42 | frames.append((fin, opcode, payload, compressed)) |
| 43 | |
| 44 | with mock.patch.object(self, "_handle_frame", _handle_frame): |
| 45 | self._feed_data(data) |
| 46 | return frames |
| 47 | |
| 48 | |
| 49 | def build_frame( |
no outgoing calls