Check that the close code has a valid value for a close frame. Raises: ProtocolError: If the close code is invalid.
(self)
| 416 | return struct.pack("!H", self.code) + self.reason.encode() |
| 417 | |
| 418 | def check(self) -> None: |
| 419 | """ |
| 420 | Check that the close code has a valid value for a close frame. |
| 421 | |
| 422 | Raises: |
| 423 | ProtocolError: If the close code is invalid. |
| 424 | |
| 425 | """ |
| 426 | if not (self.code in EXTERNAL_CLOSE_CODES or 3000 <= self.code < 5000): |
| 427 | raise ProtocolError("invalid status code") |
| 428 | |
| 429 | |
| 430 | # At the bottom to break import cycles created by type annotations. |