websocket/_abnf.py

The _abnf.py file

class websocket._abnf.ABNF(fin: int = 0, rsv1: int = 0, rsv2: int = 0, rsv3: int = 0, opcode: int = 1, mask_value: int = 1, data: str | bytes | None = '')[source]

ABNF frame class. See http://tools.ietf.org/html/rfc5234 and http://tools.ietf.org/html/rfc6455#section-5.2

__init__(fin: int = 0, rsv1: int = 0, rsv2: int = 0, rsv3: int = 0, opcode: int = 1, mask_value: int = 1, data: str | bytes | None = '') None[source]

Constructor for ABNF. Please check RFC for arguments.

static create_frame(data: bytes | str, opcode: int, fin: int = 1) ABNF[source]

Create frame to send text, binary and other data.

Parameters:
  • data (str) – data to send. This is string value(byte array). If opcode is OPCODE_TEXT and this value is unicode, data value is converted into unicode string, automatically.

  • opcode (int) – operation code. please see OPCODE_MAP.

  • fin (int) – fin flag. if set to 0, create continue fragmentation.

format() bytes[source]

Format this object to string(byte array) to send data to server.

static mask(mask_key: str | bytes, data: str | bytes) bytes[source]

Mask or unmask data. Just do xor for each byte

Parameters:
  • mask_key (bytes or str) – 4 byte mask.

  • data (bytes or str) – data to mask/unmask.

validate(skip_utf8_validation: bool = False) None[source]

Validate the ABNF frame.

Parameters:

skip_utf8_validation (skip utf8 validation.)