Check that reserved bits and opcode have acceptable values. Raises: ProtocolError: If a reserved bit or the opcode is invalid.
(self)
| 332 | return output.getvalue() |
| 333 | |
| 334 | def check(self) -> None: |
| 335 | """ |
| 336 | Check that reserved bits and opcode have acceptable values. |
| 337 | |
| 338 | Raises: |
| 339 | ProtocolError: If a reserved bit or the opcode is invalid. |
| 340 | |
| 341 | """ |
| 342 | if self.rsv1 or self.rsv2 or self.rsv3: |
| 343 | raise ProtocolError("reserved bits must be 0") |
| 344 | |
| 345 | if self.opcode in CTRL_OPCODES: |
| 346 | if len(self.data) > 125: |
| 347 | raise ProtocolError("control frame too long") |
| 348 | if not self.fin: |
| 349 | raise ProtocolError("fragmented control frame") |
| 350 | |
| 351 | |
| 352 | @dataclasses.dataclass |