MCPcopy Index your code
hub / github.com/python-websockets/websockets / parse

Method parse

src/websockets/frames.py:385–408  ·  view source on GitHub ↗

Parse the payload of a close frame. Args: data: Payload of the close frame. Raises: ProtocolError: If data is ill-formed. UnicodeDecodeError: If the reason isn't valid UTF-8.

(cls, data: BytesLike)

Source from the content-addressed store, hash-verified

383
384 @classmethod
385 def parse(cls, data: BytesLike) -> Close:
386 """
387 Parse the payload of a close frame.
388
389 Args:
390 data: Payload of the close frame.
391
392 Raises:
393 ProtocolError: If data is ill-formed.
394 UnicodeDecodeError: If the reason isn't valid UTF-8.
395
396 """
397 if isinstance(data, memoryview):
398 raise AssertionError("only compressed outgoing frames use memoryview")
399 if len(data) >= 2:
400 (code,) = struct.unpack("!H", data[:2])
401 reason = data[2:].decode()
402 close = cls(code, reason)
403 close.check()
404 return close
405 elif len(data) == 0:
406 return cls(CloseCode.NO_STATUS_RCVD, "")
407 else:
408 raise ProtocolError("close frame too short")
409
410 def serialize(self) -> bytes:
411 """

Callers

nothing calls this directly

Calls 3

ProtocolErrorClass · 0.85
decodeMethod · 0.45
checkMethod · 0.45

Tested by

no test coverage detected