431 frag_opcode, frag = -1, bytearray()
434 fin, opcode, p = WsFrames.read(rx, self.
options.max_message_bytes)
435 if opcode == WsFrames.PING:
436 self.
_write(WsFrames.encode(WsFrames.PONG, p))
437 elif opcode == WsFrames.PONG:
439 elif opcode == WsFrames.CLOSE:
440 self.
_write(WsFrames.encode(WsFrames.CLOSE, p))
442 elif opcode
in (WsFrames.TEXT, WsFrames.BINARY, WsFrames.CONT):
443 op = frag_opcode
if opcode == WsFrames.CONT
else opcode
445 raise ConnectionError(
"WebSocket continuation without a first frame")
449 if len(frag) > self.
options.max_message_bytes:
450 raise ConnectionError(
"WebSocket message too long")
454 p, frag = bytes(frag), bytearray()
456 if op == WsFrames.TEXT:
457 self.
sink.on_text(p.decode(
"utf-8",
"replace"))
459 self.
sink.on_bytes(p)
461 raise ConnectionError(
"WebSocket opcode %d" % opcode)