autobahn.websocket

Submodules

autobahn.websocket.compress

class autobahn.websocket.compress.PerMessageCompressOffer[source]

Bases: object

Base class for WebSocket compression parameter client offers.

class autobahn.websocket.compress.PerMessageCompressOfferAccept[source]

Bases: object

Base class for WebSocket compression parameter client offer accepts by the server.

class autobahn.websocket.compress.PerMessageCompressResponse[source]

Bases: object

Base class for WebSocket compression parameter server responses.

class autobahn.websocket.compress.PerMessageCompressResponseAccept[source]

Bases: object

Base class for WebSocket compression parameter server response accepts by client.

class autobahn.websocket.compress.PerMessageCompress[source]

Bases: object

Base class for WebSocket compression negotiated parameters.

class autobahn.websocket.compress.PerMessageDeflateOffer(acceptNoContextTakeover=True, acceptMaxWindowBits=True, requestNoContextTakeover=False, requestMaxWindowBits=0)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOffer, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of extension parameters for permessage-deflate WebSocket extension offered by a client to a server.

Constructor.

Parameters:
  • acceptNoContextTakeover (bool) – Iff true, client accepts “no context takeover” feature.
  • acceptMaxWindowBits (bool) – Iff true, client accepts setting “max window size”.
  • requestNoContextTakeover (bool) – Iff true, client request “no context takeover” feature.
  • requestMaxWindowBits (int) – Iff non-zero, client requests given “max window size” - must be 8-15.
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
classmethod parse(params)[source]

Parses a WebSocket extension offer for permessage-deflate provided by a client to a server.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageDeflateOffer.
class autobahn.websocket.compress.PerMessageDeflateOfferAccept(offer, requestNoContextTakeover=False, requestMaxWindowBits=0, noContextTakeover=None, windowBits=None, memLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOfferAccept, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of parameters with which to accept an permessage-deflate offer from a client by a server.

Constructor.

Parameters:
  • offer (Instance of autobahn.compress.PerMessageDeflateOffer.) – The offer being accepted.
  • requestNoContextTakeover (bool) – Iff true, server request “no context takeover” feature.
  • requestMaxCompressLevel (int) – Iff non-zero, server requests given “maximum compression level” - must be 1-9.
  • noContextTakeover (bool) – Override server (“server-to-client direction”) context takeover (this must be compatible with offer).
  • windowBits (int) – Override server (“server-to-client direction”) window size (this must be compatible with offer).
  • memLevel (int) – Set server (“server-to-client direction”) memory level.
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
class autobahn.websocket.compress.PerMessageDeflateResponse(client_max_window_bits, client_no_context_takeover, server_max_window_bits, server_no_context_takeover)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponse, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of parameters for permessage-deflate responded by server.

classmethod parse(params)[source]

Parses a WebSocket extension response for permessage-deflate provided by a server to a client.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageDeflateResponse.
class autobahn.websocket.compress.PerMessageDeflateResponseAccept(response, noContextTakeover=None, windowBits=None, memLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponseAccept, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of parameters with which to accept an permessage-deflate response from a server by a client.

Constructor.

Parameters:
  • response (Instance of autobahn.compress.PerMessageDeflateResponse.) – The response being accepted.
  • noContextTakeover (bool) – Override client (“client-to-server direction”) context takeover (this must be compatible with response).
  • windowBits (int) – Override client (“client-to-server direction”) window size (this must be compatible with response).
  • memLevel (int) – Set client (“client-to-server direction”) memory level.
class autobahn.websocket.compress.PerMessageDeflate(isServer, server_no_context_takeover, client_no_context_takeover, server_max_window_bits, client_max_window_bits, mem_level)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompress, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

permessage-deflate WebSocket extension processor.

DEFAULT_MEM_LEVEL = 8
DEFAULT_WINDOW_BITS = 15
compressMessageData(data)[source]
classmethod createFromOfferAccept(isServer, accept)[source]
classmethod createFromResponseAccept(isServer, accept)[source]
decompressMessageData(data)[source]
endCompressMessage()[source]
endDecompressMessage()[source]
startCompressMessage()[source]
startDecompressMessage()[source]
class autobahn.websocket.compress.PerMessageBzip2Offer(acceptMaxCompressLevel=True, requestMaxCompressLevel=0)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOffer, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of extension parameters for permessage-bzip2 WebSocket extension offered by a client to a server.

Constructor.

Parameters:
  • acceptMaxCompressLevel (bool) – Iff true, client accepts “maximum compression level” parameter.
  • requestMaxCompressLevel (int) – Iff non-zero, client requests given “maximum compression level” - must be 1-9.
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
classmethod parse(params)[source]

Parses a WebSocket extension offer for permessage-bzip2 provided by a client to a server.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageBzip2Offer.
class autobahn.websocket.compress.PerMessageBzip2OfferAccept(offer, requestMaxCompressLevel=0, compressLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOfferAccept, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of parameters with which to accept an permessage-bzip2 offer from a client by a server.

Constructor.

Parameters:
  • offer (Instance of autobahn.compress.PerMessageBzip2Offer.) – The offer being accepted.
  • requestMaxCompressLevel (int) – Iff non-zero, server requests given “maximum compression level” - must be 1-9.
  • compressLevel (int) – Override server (“server-to-client direction”) compress level (this must be compatible with offer).
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
class autobahn.websocket.compress.PerMessageBzip2Response(client_max_compress_level, server_max_compress_level)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponse, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of parameters for permessage-bzip2 responded by server.

classmethod parse(params)[source]

Parses a WebSocket extension response for permessage-bzip2 provided by a server to a client.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageBzip2Response.
class autobahn.websocket.compress.PerMessageBzip2ResponseAccept(response, compressLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponseAccept, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of parameters with which to accept an permessage-bzip2 response from a server by a client.

Constructor.

Parameters:
  • response (Instance of autobahn.compress.PerMessageBzip2Response.) – The response being accepted.
  • compressLevel (int) – Override client (“client-to-server direction”) compress level (this must be compatible with response).
class autobahn.websocket.compress.PerMessageBzip2(isServer, server_max_compress_level, client_max_compress_level)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompress, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

permessage-bzip2 WebSocket extension processor.

DEFAULT_COMPRESS_LEVEL = 9
compressMessageData(data)[source]
classmethod createFromOfferAccept(isServer, accept)[source]
classmethod createFromResponseAccept(isServer, accept)[source]
decompressMessageData(data)[source]
endCompressMessage()[source]
endDecompressMessage()[source]
startCompressMessage()[source]
startDecompressMessage()[source]

autobahn.websocket.compress_base

class autobahn.websocket.compress_base.PerMessageCompressOffer[source]

Bases: object

Base class for WebSocket compression parameter client offers.

class autobahn.websocket.compress_base.PerMessageCompressOfferAccept[source]

Bases: object

Base class for WebSocket compression parameter client offer accepts by the server.

class autobahn.websocket.compress_base.PerMessageCompressResponse[source]

Bases: object

Base class for WebSocket compression parameter server responses.

class autobahn.websocket.compress_base.PerMessageCompressResponseAccept[source]

Bases: object

Base class for WebSocket compression parameter server response accepts by client.

class autobahn.websocket.compress_base.PerMessageCompress[source]

Bases: object

Base class for WebSocket compression negotiated parameters.

autobahn.websocket.compress_bzip2

class autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin[source]

Bases: object

Mixin class for this extension.

EXTENSION_NAME = 'permessage-bzip2'

Name of this WebSocket extension.

COMPRESS_LEVEL_PERMISSIBLE_VALUES = [1, 2, 3, 4, 5, 6, 7, 8, 9]

Permissible value for compression level parameter.

class autobahn.websocket.compress_bzip2.PerMessageBzip2Offer(acceptMaxCompressLevel=True, requestMaxCompressLevel=0)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOffer, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of extension parameters for permessage-bzip2 WebSocket extension offered by a client to a server.

Constructor.

Parameters:
  • acceptMaxCompressLevel (bool) – Iff true, client accepts “maximum compression level” parameter.
  • requestMaxCompressLevel (int) – Iff non-zero, client requests given “maximum compression level” - must be 1-9.
classmethod parse(params)[source]

Parses a WebSocket extension offer for permessage-bzip2 provided by a client to a server.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageBzip2Offer.
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
class autobahn.websocket.compress_bzip2.PerMessageBzip2OfferAccept(offer, requestMaxCompressLevel=0, compressLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOfferAccept, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of parameters with which to accept an permessage-bzip2 offer from a client by a server.

Constructor.

Parameters:
  • offer (Instance of autobahn.compress.PerMessageBzip2Offer.) – The offer being accepted.
  • requestMaxCompressLevel (int) – Iff non-zero, server requests given “maximum compression level” - must be 1-9.
  • compressLevel (int) – Override server (“server-to-client direction”) compress level (this must be compatible with offer).
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
class autobahn.websocket.compress_bzip2.PerMessageBzip2Response(client_max_compress_level, server_max_compress_level)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponse, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of parameters for permessage-bzip2 responded by server.

classmethod parse(params)[source]

Parses a WebSocket extension response for permessage-bzip2 provided by a server to a client.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageBzip2Response.
class autobahn.websocket.compress_bzip2.PerMessageBzip2ResponseAccept(response, compressLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponseAccept, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

Set of parameters with which to accept an permessage-bzip2 response from a server by a client.

Constructor.

Parameters:
  • response (Instance of autobahn.compress.PerMessageBzip2Response.) – The response being accepted.
  • compressLevel (int) – Override client (“client-to-server direction”) compress level (this must be compatible with response).
class autobahn.websocket.compress_bzip2.PerMessageBzip2(isServer, server_max_compress_level, client_max_compress_level)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompress, autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin

permessage-bzip2 WebSocket extension processor.

DEFAULT_COMPRESS_LEVEL = 9
classmethod createFromResponseAccept(isServer, accept)[source]
classmethod createFromOfferAccept(isServer, accept)[source]
startCompressMessage()[source]
compressMessageData(data)[source]
endCompressMessage()[source]
startDecompressMessage()[source]
decompressMessageData(data)[source]
endDecompressMessage()[source]

autobahn.websocket.compress_deflate

class autobahn.websocket.compress_deflate.PerMessageDeflateMixin[source]

Bases: object

Mixin class for this extension.

EXTENSION_NAME = 'permessage-deflate'

Name of this WebSocket extension.

WINDOW_SIZE_PERMISSIBLE_VALUES = [8, 9, 10, 11, 12, 13, 14, 15]

Permissible value for window size parameter. Higher values use more memory, but produce smaller output. The default is 15.

MEM_LEVEL_PERMISSIBLE_VALUES = [1, 2, 3, 4, 5, 6, 7, 8, 9]

Permissible value for memory level parameter. Higher values use more memory, but are faster and produce smaller output. The default is 8.

class autobahn.websocket.compress_deflate.PerMessageDeflateOffer(acceptNoContextTakeover=True, acceptMaxWindowBits=True, requestNoContextTakeover=False, requestMaxWindowBits=0)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOffer, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of extension parameters for permessage-deflate WebSocket extension offered by a client to a server.

Constructor.

Parameters:
  • acceptNoContextTakeover (bool) – Iff true, client accepts “no context takeover” feature.
  • acceptMaxWindowBits (bool) – Iff true, client accepts setting “max window size”.
  • requestNoContextTakeover (bool) – Iff true, client request “no context takeover” feature.
  • requestMaxWindowBits (int) – Iff non-zero, client requests given “max window size” - must be 8-15.
classmethod parse(params)[source]

Parses a WebSocket extension offer for permessage-deflate provided by a client to a server.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageDeflateOffer.
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
class autobahn.websocket.compress_deflate.PerMessageDeflateOfferAccept(offer, requestNoContextTakeover=False, requestMaxWindowBits=0, noContextTakeover=None, windowBits=None, memLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOfferAccept, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of parameters with which to accept an permessage-deflate offer from a client by a server.

Constructor.

Parameters:
  • offer (Instance of autobahn.compress.PerMessageDeflateOffer.) – The offer being accepted.
  • requestNoContextTakeover (bool) – Iff true, server request “no context takeover” feature.
  • requestMaxCompressLevel (int) – Iff non-zero, server requests given “maximum compression level” - must be 1-9.
  • noContextTakeover (bool) – Override server (“server-to-client direction”) context takeover (this must be compatible with offer).
  • windowBits (int) – Override server (“server-to-client direction”) window size (this must be compatible with offer).
  • memLevel (int) – Set server (“server-to-client direction”) memory level.
getExtensionString()[source]

Returns the WebSocket extension configuration string as sent to the server.

Returns:str – PMCE configuration string.
class autobahn.websocket.compress_deflate.PerMessageDeflateResponse(client_max_window_bits, client_no_context_takeover, server_max_window_bits, server_no_context_takeover)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponse, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of parameters for permessage-deflate responded by server.

classmethod parse(params)[source]

Parses a WebSocket extension response for permessage-deflate provided by a server to a client.

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageDeflateResponse.
class autobahn.websocket.compress_deflate.PerMessageDeflateResponseAccept(response, noContextTakeover=None, windowBits=None, memLevel=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponseAccept, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

Set of parameters with which to accept an permessage-deflate response from a server by a client.

Constructor.

Parameters:
  • response (Instance of autobahn.compress.PerMessageDeflateResponse.) – The response being accepted.
  • noContextTakeover (bool) – Override client (“client-to-server direction”) context takeover (this must be compatible with response).
  • windowBits (int) – Override client (“client-to-server direction”) window size (this must be compatible with response).
  • memLevel (int) – Set client (“client-to-server direction”) memory level.
class autobahn.websocket.compress_deflate.PerMessageDeflate(isServer, server_no_context_takeover, client_no_context_takeover, server_max_window_bits, client_max_window_bits, mem_level)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompress, autobahn.websocket.compress_deflate.PerMessageDeflateMixin

permessage-deflate WebSocket extension processor.

DEFAULT_WINDOW_BITS = 15
DEFAULT_MEM_LEVEL = 8
classmethod createFromResponseAccept(isServer, accept)[source]
classmethod createFromOfferAccept(isServer, accept)[source]
startCompressMessage()[source]
compressMessageData(data)[source]
endCompressMessage()[source]
startDecompressMessage()[source]
decompressMessageData(data)[source]
endDecompressMessage()[source]

autobahn.websocket.compress_snappy

autobahn.websocket.http

exception autobahn.websocket.http.HttpException(code, reason)[source]

Bases: exceptions.Exception

Throw an instance of this class to deny a WebSocket connection during handshake in autobahn.websocket.protocol.WebSocketServerProtocol.onConnect().

Constructor.

Parameters:
  • code (int) – HTTP error code.
  • reason (str) – HTTP error reason.

autobahn.websocket.interfaces

class autobahn.websocket.interfaces.IWebSocketChannel[source]

Bases: object

A WebSocket channel is a bidirectional, full-duplex, ordered, reliable message channel over a WebSocket connection as specified in RFC6455.

This interface defines a message-based API to WebSocket plus auxiliary hooks and methods.

onConnect(requestOrResponse)[source]

Callback fired during WebSocket opening handshake when a client connects (to a server with request from client) or when server connection established (by a client with response from server).

Parameters:requestOrResponse (Instance of autobahn.websocket.protocol.ConnectionRequest or autobahn.websocket.protocol.ConnectionResponse.) – Connection request (for servers) or response (for clients).
Returns:When this callback is fired on a WebSocket server, you may return one of the following:
  1. None: Connection accepted (no subprotocol)
  2. str: Connection accepted with given subprotocol
  3. (subprotocol, headers): Connection accepted with given subprotocol (which also may be None) and set the given HTTP headers (e.g. cookies). headers must be a dict with str keys and values for the HTTP header values to set.

    If a given header value is a non-string iterable (e.g. list or tuple), a separate header line will be sent for each item in the iterable.

If the client announced one or multiple subprotocols, the server MUST select one of the given list.

onOpen()[source]

Callback fired when the initial WebSocket opening handshake was completed. You now can send and receive WebSocket messages.

sendMessage(payload, isBinary=False, fragmentSize=None, sync=False, doNotCompress=False)[source]

Send a WebSocket message over the connection to the peer.

Parameters:
  • payload (bytes) – The message payload.
  • isBinary (bool) – True when payload is binary, else the payload must be UTF-8 encoded text.
  • fragmentSize (int) – Fragment message into WebSocket fragments of this size (the last frame potentially being shorter).
  • sync (bool) –

    If True, try to force data onto the wire immediately.

    Warning

    Do NOT use this feature for normal applications. Performance likely will suffer significantly. This feature is mainly here for use by Autobahn|Testsuite.

  • doNotCompress (bool) – Iff True, never compress this message. This only applies to Hybi-Mode and only when WebSocket compression has been negotiated on the WebSocket connection. Use when you know the payload incompressible (e.g. encrypted or already compressed).
onMessage(payload, isBinary)[source]

Callback fired when a complete WebSocket message was received.

Parameters:
  • payload (bytes) – Message payload (UTF-8 encoded text or binary). Can also be empty when the WebSocket message contained no payload.
  • isBinary (bool) – True iff payload is binary, else the payload is UTF-8 encoded text.
sendClose(code=None, reason=None)[source]

Starts a WebSocket closing handshake tearing down the WebSocket connection.

Parameters:
  • code (int) – An optional close status code (1000 for normal close or 3000-4999 for application specific close).
  • reason (str) – An optional close reason (a string that when present, a status code MUST also be present).
onClose(wasClean, code, reason)[source]

Callback fired when the WebSocket connection has been closed (WebSocket closing handshake has been finished or the connection was closed uncleanly).

Parameters:
  • wasClean (bool) – True iff the WebSocket connection was closed cleanly.
  • code (int or None) – Close status code (as sent by the WebSocket peer).
  • reason (unicode or None) – Close reason (as sent by the WebSocket peer).
sendPreparedMessage(preparedMsg)[source]

Send a message that was previously prepared with autobahn.websocket.protocol.WebSocketFactory.prepareMessage().

Parameters:prepareMessage (Instance of autobahn.websocket.protocol.PreparedMessage.) – A previously prepared message.
sendPing(payload=None)[source]

Send a WebSocket ping to the peer.

A peer is expected to pong back the payload a soon as “practical”. When more than one ping is outstanding at a peer, the peer may elect to respond only to the last ping.

Parameters:payload (bytes or None) – An (optional) arbitrary payload of length less than 126 octets.
onPing(payload)[source]

Callback fired when a WebSocket ping was received. A default implementation responds by sending a WebSocket pong.

Parameters:payload (bytes) – Payload of ping (when there was any). Can be arbitrary, up to 125 octets.
sendPong(payload=None)[source]

Send a WebSocket pong to the peer.

A WebSocket pong may be sent unsolicited. This serves as a unidirectional heartbeat. A response to an unsolicited pong is “not expected”.

Parameters:payload (bytes) – An (optional) arbitrary payload of length < 126 octets.
onPong(payload)[source]

Callback fired when a WebSocket pong was received. A default implementation does nothing.

Parameters:payload (bytes) – Payload of pong (when there was any). Can be arbitrary, up to 125 octets.
class autobahn.websocket.interfaces.IWebSocketChannelFrameApi[source]

Bases: autobahn.websocket.interfaces.IWebSocketChannel

Frame-based API to a WebSocket channel.

onMessageBegin(isBinary)[source]

Callback fired when receiving of a new WebSocket message has begun.

Parameters:isBinary (bool) – True if payload is binary, else the payload is UTF-8 encoded text.
onMessageFrame(payload)[source]

Callback fired when a complete WebSocket message frame for a previously begun WebSocket message has been received.

Parameters:payload (list of bytes) – Message frame payload (a list of chunks received).
onMessageEnd()[source]

Callback fired when a WebSocket message has been completely received (the last WebSocket frame for that message has been received).

beginMessage(isBinary=False, doNotCompress=False)[source]

Begin sending a new WebSocket message.

Parameters:
  • isBinary (bool) – True if payload is binary, else the payload must be UTF-8 encoded text.
  • doNotCompress (bool) – If True, never compress this message. This only applies to Hybi-Mode and only when WebSocket compression has been negotiated on the WebSocket connection. Use when you know the payload incompressible (e.g. encrypted or already compressed).
sendMessageFrame(payload, sync=False)[source]

When a message has been previously begun, send a complete message frame in one go.

Parameters:
  • payload (bytes) – The message frame payload. When sending a text message, the payload must be UTF-8 encoded already.
  • sync (bool) –

    If True, try to force data onto the wire immediately.

    Warning

    Do NOT use this feature for normal applications. Performance likely will suffer significantly. This feature is mainly here for use by Autobahn|Testsuite.

endMessage()[source]

End a message previously begun message. No more frames may be sent (for that message). You have to begin a new message before sending again.

class autobahn.websocket.interfaces.IWebSocketChannelStreamingApi[source]

Bases: autobahn.websocket.interfaces.IWebSocketChannelFrameApi

Streaming API to a WebSocket channel.

onMessageFrameBegin(length)[source]

Callback fired when receiving a new message frame has begun. A default implementation will prepare to buffer message frame data.

Parameters:length (int) – Payload length of message frame which is subsequently received.
onMessageFrameData(payload)[source]

Callback fired when receiving data within a previously begun message frame. A default implementation will buffer data for frame.

Parameters:payload (bytes) – Partial payload for message frame.
onMessageFrameEnd()[source]

Callback fired when a previously begun message frame has been completely received. A default implementation will flatten the buffered frame data and fire onMessageFrame.

beginMessageFrame(length)[source]

Begin sending a new message frame.

Parameters:length (int) – Length of the frame which is to be started. Must be less or equal 2^63.
sendMessageFrameData(payload, sync=False)[source]

Send out data when within a message frame (message was begun, frame was begun). Note that the frame is automatically ended when enough data has been sent. In other words, there is no endMessageFrame, since you have begun the frame specifying the frame length, which implicitly defined the frame end. This is different from messages, which you begin and end explicitly , since a message can contain an unlimited number of frames.

Parameters:
  • payload (bytes) – Frame payload to send.
  • sync (bool) –

    If True, try to force data onto the wire immediately.

    Warning

    Do NOT use this feature for normal applications. Performance likely will suffer significantly. This feature is mainly here for use by Autobahn|Testsuite.

Returns:

When the currently sent message frame is still incomplete, returns octets remaining to be sent. When the frame is complete, returns 0. Otherwise the amount of unconsumed data in payload argument is returned.

Return type:

int

autobahn.websocket.protocol

autobahn.websocket.useragent

autobahn.websocket.useragent.lookupWsSupport(ua, debug=True)[source]

Lookup if browser supports WebSocket (Hixie76, Hybi10+, RFC6455) natively, and if not, whether the web-socket-js Flash bridge works to polyfill that.

Returns a tuple of booleans (ws_supported, needs_flash, detected) where

  • ws_supported: WebSocket is supported
  • needs_flash: Flash Bridge is needed for support
  • detected the code has explicitly mapped support
Parameters:ua (str) – The browser user agent string as sent in the HTTP header, e.g. provided as flask.request.user_agent.string in Flask.
Returns:tuple – A tuple (ws_supported, needs_flash, detected).

autobahn.websocket.utf8validator

class autobahn.websocket.utf8validator.Utf8Validator

Bases: object

Incremental UTF-8 validator with constant memory consumption (minimal state).

Implements the algorithm “Flexible and Economical UTF-8 Decoder” by Bjoern Hoehrmann (http://bjoern.hoehrmann.de/utf-8/decoder/dfa/).

UTF8_ACCEPT = 0
UTF8_REJECT = 1
codepoint
i
state
decode()

Eat one UTF-8 octet, and validate on the fly.

Returns UTF8_ACCEPT when enough octets have been consumed, in which case self.codepoint contains the decoded Unicode code point.

Returns UTF8_REJECT when invalid UTF-8 was encountered.

Returns some other positive integer when more octets need to be eaten.

reset()

Reset validator to start new incremental UTF-8 decode/validation.

validate()

Incrementally validate a chunk of bytes provided as bytearray.

Will return a quad (valid?, endsOnCodePoint?, currentIndex, totalIndex).

As soon as an octet is encountered which renders the octet sequence invalid, a quad with valid? == False is returned. currentIndex returns the index within the currently consumed chunk, and totalIndex the index within the total consumed sequence that was the point of bail out. When valid? == True, currentIndex will be len(ba) and totalIndex the total amount of consumed bytes.

autobahn.websocket.xormasker

Module contents

Reactive Manifesto: We are reactive banner