Function
_write_frame
(sock, opcode, payload=b"")
Source from the content-addressed store, hash-verified
| 50 | |
| 51 | |
| 52 | def _write_frame(sock, opcode, payload=b""): |
| 53 | frame = bytearray([0x80 | opcode]) |
| 54 | length = len(payload) |
| 55 | if length < 126: |
| 56 | frame.append(length) |
| 57 | elif length < 1 << 16: |
| 58 | frame.append(126) |
| 59 | frame.extend(struct.pack("!H", length)) |
| 60 | else: |
| 61 | frame.append(127) |
| 62 | frame.extend(struct.pack("!Q", length)) |
| 63 | frame.extend(payload) |
| 64 | sock.sendall(bytes(frame)) |
| 65 | |
| 66 | |
| 67 | def _handshake(sock, key): |
Tested by
no test coverage detected