websocket/_abnf.py

The _abnf.py file

class websocket._abnf.ABNF(fin=0, rsv1=0, rsv2=0, rsv3=0, opcode=1, mask=1, data='')[source]

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

__init__(fin=0, rsv1=0, rsv2=0, rsv3=0, opcode=1, mask=1, data='')[source]

Constructor for ABNF. Please check RFC for arguments.

static create_frame(data, opcode, fin=1)[source]

Create frame to send text, binary and other data.

Parameters
  • data (<type>) – 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 (<type>) – operation code. please see OPCODE_XXX.

  • fin (<type>) – fin flag. if set to 0, create continue fragmentation.

format()[source]

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

static mask(mask_key, data)[source]

Mask or unmask data. Just do xor for each byte

Parameters
  • mask_key (<type>) – 4 byte string.

  • data (<type>) – data to mask/unmask.

validate(skip_utf8_validation=False)[source]

Validate the ABNF frame.

Parameters

skip_utf8_validation (skip utf8 validation.) –