autobahn.websocket

Submodules

autobahn.websocket.compress

class autobahn.websocket.compress.PerMessageCompressOffer

Base class for WebSocket compression parameter client offers.

class autobahn.websocket.compress.PerMessageCompressOfferAccept

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

class autobahn.websocket.compress.PerMessageCompressResponse

Base class for WebSocket compression parameter server responses.

class autobahn.websocket.compress.PerMessageCompressResponseAccept

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

class autobahn.websocket.compress.PerMessageCompress

Base class for WebSocket compression negotiated parameters.

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

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()

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

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

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)

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()

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)

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

Set of parameters for permessage-deflate responded by server.

classmethod parse(params)

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)

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)

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)
classmethod createFromOfferAccept(isServer, accept)
classmethod createFromResponseAccept(isServer, accept)
decompressMessageData(data)
endCompressMessage()
endDecompressMessage()
startCompressMessage()
startDecompressMessage()
class autobahn.websocket.compress.PerMessageBzip2Offer(acceptMaxCompressLevel=True, requestMaxCompressLevel=0)

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()

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

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

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)

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()

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)

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

Set of parameters for permessage-bzip2 responded by server.

classmethod parse(params)

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)

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)

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

permessage-bzip2 WebSocket extension processor.

DEFAULT_COMPRESS_LEVEL = 9
compressMessageData(data)
classmethod createFromOfferAccept(isServer, accept)
classmethod createFromResponseAccept(isServer, accept)
decompressMessageData(data)
endCompressMessage()
endDecompressMessage()
startCompressMessage()
startDecompressMessage()
class autobahn.websocket.compress.PerMessageSnappyOffer(acceptNoContextTakeover=True, requestNoContextTakeover=False)

Bases: autobahn.websocket.compress_base.PerMessageCompressOffer, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

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

Constructor.

Parameters:
  • acceptNoContextTakeover (bool) – Iff true, client accepts “no context takeover” feature.
  • requestNoContextTakeover (bool) – Iff true, client request “no context takeover” feature.
getExtensionString()

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

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

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

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageSnappyOffer.
class autobahn.websocket.compress.PerMessageSnappyOfferAccept(offer, requestNoContextTakeover=False, noContextTakeover=None)

Bases: autobahn.websocket.compress_base.PerMessageCompressOfferAccept, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

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

Constructor.

Parameters:
  • offer (Instance of autobahn.compress.PerMessageSnappyOffer.) – The offer being accepted.
  • requestNoContextTakeover (bool) – Iff true, server request “no context takeover” feature.
  • noContextTakeover (bool) – Override server (“server-to-client direction”) context takeover (this must be compatible with offer).
getExtensionString()

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

Returns:str – PMCE configuration string.
class autobahn.websocket.compress.PerMessageSnappyResponse(client_no_context_takeover, server_no_context_takeover)

Bases: autobahn.websocket.compress_base.PerMessageCompressResponse, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

Set of parameters for permessage-snappy responded by server.

classmethod parse(params)

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

Parameters:params (list) – Output from autobahn.websocket.WebSocketProtocol._parseExtensionsHeader().
Returns:object – A new instance of autobahn.compress.PerMessageSnappyResponse.
class autobahn.websocket.compress.PerMessageSnappyResponseAccept(response, noContextTakeover=None)

Bases: autobahn.websocket.compress_base.PerMessageCompressResponseAccept, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

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

Constructor.

Parameters:
  • response (Instance of autobahn.compress.PerMessageSnappyResponse.) – The response being accepted.
  • noContextTakeover (bool) – Override client (“client-to-server direction”) context takeover (this must be compatible with response).
class autobahn.websocket.compress.PerMessageSnappy(isServer, server_no_context_takeover, client_no_context_takeover)

Bases: autobahn.websocket.compress_base.PerMessageCompress, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

permessage-snappy WebSocket extension processor.

compressMessageData(data)
classmethod createFromOfferAccept(isServer, accept)
classmethod createFromResponseAccept(isServer, accept)
decompressMessageData(data)
endCompressMessage()
endDecompressMessage()
startCompressMessage()
startDecompressMessage()

autobahn.websocket.compress_base

class autobahn.websocket.compress_base.PerMessageCompressOffer[source]

Base class for WebSocket compression parameter client offers.

class autobahn.websocket.compress_base.PerMessageCompressOfferAccept[source]

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

class autobahn.websocket.compress_base.PerMessageCompressResponse[source]

Base class for WebSocket compression parameter server responses.

class autobahn.websocket.compress_base.PerMessageCompressResponseAccept[source]

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

class autobahn.websocket.compress_base.PerMessageCompress[source]

Base class for WebSocket compression negotiated parameters.

autobahn.websocket.compress_bzip2

class autobahn.websocket.compress_bzip2.PerMessageBzip2Mixin[source]

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]

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

class autobahn.websocket.compress_snappy.PerMessageSnappyMixin[source]

Mixin class for this extension.

EXTENSION_NAME = 'permessage-snappy'

Name of this WebSocket extension.

class autobahn.websocket.compress_snappy.PerMessageSnappyOffer(acceptNoContextTakeover=True, requestNoContextTakeover=False)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOffer, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

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

Constructor.

Parameters:
  • acceptNoContextTakeover (bool) – Iff true, client accepts “no context takeover” feature.
  • requestNoContextTakeover (bool) – Iff true, client request “no context takeover” feature.
classmethod parse(params)[source]

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

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

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

Returns:str – PMCE configuration string.
class autobahn.websocket.compress_snappy.PerMessageSnappyOfferAccept(offer, requestNoContextTakeover=False, noContextTakeover=None)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressOfferAccept, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

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

Constructor.

Parameters:
  • offer (Instance of autobahn.compress.PerMessageSnappyOffer.) – The offer being accepted.
  • requestNoContextTakeover (bool) – Iff true, server request “no context takeover” feature.
  • noContextTakeover (bool) – Override server (“server-to-client direction”) context takeover (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_snappy.PerMessageSnappyResponse(client_no_context_takeover, server_no_context_takeover)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompressResponse, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

Set of parameters for permessage-snappy responded by server.

classmethod parse(params)[source]

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

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

Bases: autobahn.websocket.compress_base.PerMessageCompressResponseAccept, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

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

Constructor.

Parameters:
  • response (Instance of autobahn.compress.PerMessageSnappyResponse.) – The response being accepted.
  • noContextTakeover (bool) – Override client (“client-to-server direction”) context takeover (this must be compatible with response).
class autobahn.websocket.compress_snappy.PerMessageSnappy(isServer, server_no_context_takeover, client_no_context_takeover)[source]

Bases: autobahn.websocket.compress_base.PerMessageCompress, autobahn.websocket.compress_snappy.PerMessageSnappyMixin

permessage-snappy WebSocket extension processor.

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.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.protocol.createWsUrl(hostname, port=None, isSecure=False, path=None, params=None)[source]

Create a WebSocket URL from components.

Parameters:
  • hostname (str) – WebSocket server hostname.
  • port (int) – WebSocket service port or None (to select default ports 80/443 depending on isSecure).
  • isSecure (bool) – Set True for secure WebSocket (“wss” scheme).
  • path (str) – Path component of addressed resource (will be properly URL escaped).
  • params (dict) – A dictionary of key-values to construct the query component of the addressed resource (will be properly URL escaped).
Returns:

str – Constructed WebSocket URL.

autobahn.websocket.protocol.parseWsUrl(url)[source]

Parses as WebSocket URL into it’s components and returns a tuple (isSecure, host, port, resource, path, params).

isSecure is a flag which is True for wss URLs. host is the hostname or IP from the URL. port is the port from the URL or standard port derived from scheme (ws = 80, wss = 443). resource is the /resource name/ from the URL, the /path/ together with the (optional) /query/ component. path is the /path/ component properly unescaped. params is the /query) component properly unescaped and returned as dictionary.

Parameters:url (str) – A valid WebSocket URL, i.e. ws://localhost:9000/myresource?param1=23&param2=666
Returns:tuple – A tuple (isSecure, host, port, resource, path, params)
class autobahn.websocket.protocol.ConnectionRequest(peer, headers, host, path, params, version, origin, protocols, extensions)[source]

Thin-wrapper for WebSocket connection request information provided in autobahn.websocket.protocol.WebSocketServerProtocol.onConnect() when a WebSocket client want to establish a connection to a WebSocket server.

Constructor.

Parameters:
  • peer (str) – Descriptor of the connecting client (e.g. IP address/port in case of TCP transports).
  • headers (dict) – HTTP headers from opening handshake request.
  • host (str) – Host from opening handshake HTTP header.
  • path (str) – Path from requested HTTP resource URI. For example, a resource URI of /myservice?foo=23&foo=66&bar=2 will be parsed to /myservice.
  • params (dict of arrays of strings) – Query parameters (if any) from requested HTTP resource URI. For example, a resource URI of /myservice?foo=23&foo=66&bar=2 will be parsed to {‘foo’: [‘23’, ‘66’], ‘bar’: [‘2’]}.
  • version (int) – The WebSocket protocol version the client announced (and will be spoken, when connection is accepted).
  • origin (str) – The WebSocket origin header or None. Note that this only a reliable source of information for browser clients!
  • protocols (list of str) – The WebSocket (sub)protocols the client announced. You must select and return one of those (or None) in autobahn.websocket.WebSocketServerProtocol.onConnect().
  • extensions (list of str) – The WebSocket extensions the client requested and the server accepted (and thus will be spoken, when WS connection is established).
class autobahn.websocket.protocol.ConnectionResponse(peer, headers, version, protocol, extensions)[source]

Thin-wrapper for WebSocket connection response information provided in autobahn.websocket.protocol.WebSocketClientProtocol.onConnect() when a WebSocket server has accepted a connection request by a client.

Constructor.

Parameters:
  • peer (str) – Descriptor of the connected server (e.g. IP address/port in case of TCP transport).
  • headers (dict) – HTTP headers from opening handshake response.
  • version (int) – The WebSocket protocol version that is spoken.
  • protocol (str) – The WebSocket (sub)protocol in use.
  • extensions (list of str) – The WebSocket extensions in use.
class autobahn.websocket.protocol.Timings[source]

Helper class to track timings by key. This class also supports item access, iteration and conversion to string.

track(key)[source]

Track elapsed for key.

Parameters:key (str) – Key under which to track the timing.
diff(startKey, endKey, formatted=True)[source]

Get elapsed difference between two previously tracked keys.

Parameters:
  • startKey (str) – First key for interval (older timestamp).
  • endKey (str) – Second key for interval (younger timestamp).
  • formatted (bool) – If True, format computed time period and return string.
Returns:

float or str – Computed time period in seconds (or formatted string).

class autobahn.websocket.protocol.WebSocketProtocol[source]

Protocol base class for WebSocket.

This class implements:

SUPPORTED_SPEC_VERSIONS = [0, 10, 11, 12, 13, 14, 15, 16, 17, 18]

WebSocket protocol spec (draft) versions supported by this implementation. Use of version 18 indicates RFC6455. Use of versions < 18 indicate actual draft spec versions (Hybi-Drafts). Use of version 0 indicates Hixie-76.

SUPPORTED_PROTOCOL_VERSIONS = [0, 8, 13]

WebSocket protocol versions supported by this implementation. For Hixie-76, there is no protocol version announced in HTTP header, and we just use the draft version (0) in this case.

SPEC_TO_PROTOCOL_VERSION = {0: 0, 16: 13, 18: 13, 17: 13, 10: 8, 11: 8, 12: 8, 13: 13, 14: 13, 15: 13}

Mapping from protocol spec (draft) version to protocol version. For Hixie-76, there is no protocol version announced in HTTP header, and we just use the pseudo protocol version 0 in this case.

PROTOCOL_TO_SPEC_VERSION = {0: 0, 8: 12, 13: 18}

Mapping from protocol version to the latest protocol spec (draft) version using that protocol version. For Hixie-76, there is no protocol version announced in HTTP header, and we just use the draft version (0) in this case.

DEFAULT_SPEC_VERSION = 18

Default WebSocket protocol spec version this implementation speaks: final RFC6455.

DEFAULT_ALLOW_HIXIE76 = False

By default, this implementation will not allow to speak the obsoleted Hixie-76 protocol version. That protocol version has security issues, but is still spoken by some clients. Enable at your own risk! Enabling can be done by using setProtocolOptions() on the factories for clients and servers.

MESSAGE_TYPE_TEXT = 1

WebSocket text message type (UTF-8 payload).

MESSAGE_TYPE_BINARY = 2

WebSocket binary message type (arbitrary binary payload).

STATE_CLOSED = 0
STATE_CONNECTING = 1
STATE_CLOSING = 2
STATE_OPEN = 3
STATE_PROXY_CONNECTING = 4
SEND_STATE_GROUND = 0
SEND_STATE_MESSAGE_BEGIN = 1
SEND_STATE_INSIDE_MESSAGE = 2
SEND_STATE_INSIDE_MESSAGE_FRAME = 3
CLOSE_STATUS_CODE_NORMAL = 1000

Normal close of connection.

CLOSE_STATUS_CODE_GOING_AWAY = 1001

Going away.

CLOSE_STATUS_CODE_PROTOCOL_ERROR = 1002

Protocol error.

CLOSE_STATUS_CODE_UNSUPPORTED_DATA = 1003

Unsupported data.

CLOSE_STATUS_CODE_RESERVED1 = 1004

RESERVED

CLOSE_STATUS_CODE_NULL = 1005

No status received. (MUST NOT be used as status code when sending a close).

CLOSE_STATUS_CODE_ABNORMAL_CLOSE = 1006

Abnormal close of connection. (MUST NOT be used as status code when sending a close).

CLOSE_STATUS_CODE_INVALID_PAYLOAD = 1007

Invalid frame payload data.

CLOSE_STATUS_CODE_POLICY_VIOLATION = 1008

Policy violation.

CLOSE_STATUS_CODE_MESSAGE_TOO_BIG = 1009

Message too big.

CLOSE_STATUS_CODE_MANDATORY_EXTENSION = 1010

Mandatory extension.

CLOSE_STATUS_CODE_INTERNAL_ERROR = 1011

The peer encountered an unexpected condition or internal error.

CLOSE_STATUS_CODE_TLS_HANDSHAKE_FAILED = 1015

TLS handshake failed, i.e. server certificate could not be verified. (MUST NOT be used as status code when sending a close).

CLOSE_STATUS_CODES_ALLOWED = [1000, 1001, 1002, 1003, 1007, 1008, 1009, 1010, 1011]

Status codes allowed to send in close.

CONFIG_ATTRS_COMMON = ['debug', 'debugCodePaths', 'logOctets', 'logFrames', 'trackTimings', 'allowHixie76', 'utf8validateIncoming', 'applyMask', 'maxFramePayloadSize', 'maxMessagePayloadSize', 'autoFragmentSize', 'failByDrop', 'echoCloseCodeReason', 'openHandshakeTimeout', 'closeHandshakeTimeout', 'tcpNoDelay', 'autoPingInterval', 'autoPingTimeout', 'autoPingSize']

Configuration attributes common to servers and clients.

CONFIG_ATTRS_SERVER = ['versions', 'webStatus', 'requireMaskedClientFrames', 'maskServerFrames', 'perMessageCompressionAccept', 'serveFlashSocketPolicy', 'flashSocketPolicy', 'allowedOrigins', 'allowedOriginsPatterns']

Configuration attributes specific to servers.

CONFIG_ATTRS_CLIENT = ['version', 'acceptMaskedServerFrames', 'maskClientFrames', 'serverConnectionDropTimeout', 'perMessageCompressionOffers', 'perMessageCompressionAccept']

Configuration attributes specific to clients.

onOpen()[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onOpen()

onMessageBegin(isBinary)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessageBegin()

onMessageFrameBegin(length)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessageFrameBegin()

onMessageFrameData(payload)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessageFrameData()

onMessageFrameEnd()[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessageFrameEnd()

onMessageFrame(payload)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessageFrame()

onMessageEnd()[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessageEnd()

onMessage(payload, isBinary)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onMessage()

onPing(payload)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onPing()

onPong(payload)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onPong()

onClose(wasClean, code, reason)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.onClose()

onCloseFrame(code, reasonRaw)[source]

Callback when a Close frame was received. The default implementation answers by sending a Close when no Close was sent before. Otherwise it drops the TCP connection either immediately (when we are a server) or after a timeout (when we are a client and expect the server to drop the TCP).

Modes: Hybi, Hixie

Notes:
  • For Hixie mode, this method is slightly misnamed for historic reasons.
  • For Hixie mode, code and reasonRaw are silently ignored.
Parameters:
  • code (int or None) – Close status code, if there was one (WebSocketProtocol.CLOSE_STATUS_CODE_*).
  • reason (str or None) – Close reason (when present, a status code MUST have been also be present).
onServerConnectionDropTimeout()[source]

We (a client) expected the peer (a server) to drop the connection, but it didn’t (in time self.serverConnectionDropTimeout). So we drop the connection, but set self.wasClean = False.

Modes: Hybi, Hixie

onOpenHandshakeTimeout()[source]

We expected the peer to complete the opening handshake with to us. It didn’t do so (in time self.openHandshakeTimeout). So we drop the connection, but set self.wasClean = False.

Modes: Hybi, Hixie

onCloseHandshakeTimeout()[source]

We expected the peer to respond to us initiating a close handshake. It didn’t respond (in time self.closeHandshakeTimeout) with a close response frame though. So we drop the connection, but set self.wasClean = False.

Modes: Hybi, Hixie

onAutoPingTimeout()[source]

When doing automatic ping/pongs to detect broken connection, the peer did not reply in time to our ping. We drop the connection.

dropConnection(abort=False)[source]

Drop the underlying TCP connection.

Modes: Hybi, Hixie

failConnection(code=1001, reason='Going Away')[source]

Fails the WebSocket connection.

Modes: Hybi, Hixie

Notes:
  • For Hixie mode, the code and reason are silently ignored.
protocolViolation(reason)[source]

Fired when a WebSocket protocol violation/error occurs.

Modes: Hybi, Hixie

Notes:
  • For Hixie mode, reason is silently ignored.
Parameters:reason (str) – Protocol violation that was encountered (human readable).
Returns:bool – True, when any further processing should be discontinued.
invalidPayload(reason)[source]

Fired when invalid payload is encountered. Currently, this only happens for text message when payload is invalid UTF-8 or close frames with close reason that is invalid UTF-8.

Modes: Hybi, Hixie

Notes:
  • For Hixie mode, reason is silently ignored.
Parameters:reason (str) – What was invalid for the payload (human readable).
Returns:bool – True, when any further processing should be discontinued.
setTrackTimings(enable)[source]

Enable/disable tracking of detailed timings.

Parameters:enable (bool) – Turn time tracking on/off.
logRxOctets(data)[source]

Hook fired right after raw octets have been received, but only when self.logOctets == True.

Modes: Hybi, Hixie

logTxOctets(data, sync)[source]

Hook fired right after raw octets have been sent, but only when self.logOctets == True.

Modes: Hybi, Hixie

logRxFrame(frameHeader, payload)[source]

Hook fired right after WebSocket frame has been received and decoded, but only when self.logFrames == True.

Modes: Hybi

logTxFrame(frameHeader, payload, repeatLength, chopsize, sync)[source]

Hook fired right after WebSocket frame has been encoded and sent, but only when self.logFrames == True.

Modes: Hybi

consumeData()[source]

Consume buffered (incoming) data.

Modes: Hybi, Hixie

processProxyConnect()[source]

Process proxy connect.

Modes: Hybi, Hixie

processHandshake()[source]

Process WebSocket handshake.

Modes: Hybi, Hixie

sendData(data, sync=False, chopsize=None)[source]

Wrapper for self.transport.write which allows to give a chopsize. When asked to chop up writing to TCP stream, we write only chopsize octets and then give up control to select() in underlying reactor so that bytes get onto wire immediately. Note that this is different from and unrelated to WebSocket data message fragmentation. Note that this is also different from the TcpNoDelay option which can be set on the socket.

Modes: Hybi, Hixie

sendPreparedMessage(preparedMsg)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.sendPreparedMessage()

processData()[source]

After WebSocket handshake has been completed, this procedure will do all subsequent processing of incoming bytes.

Modes: Hybi, Hixie

processDataHixie76()[source]

Hixie-76 incoming data processing.

Modes: Hixie

processDataHybi()[source]

RFC6455/Hybi-Drafts incoming data processing.

Modes: Hybi

onFrameBegin()[source]

Begin of receive new frame.

Modes: Hybi

onFrameData(payload)[source]

New data received within frame.

Modes: Hybi

onFrameEnd()[source]

End of frame received.

Modes: Hybi

processControlFrame()[source]

Process a completely received control frame.

Modes: Hybi

sendFrame(opcode, payload='', fin=True, rsv=0, mask=None, payload_len=None, chopsize=None, sync=False)[source]

Send out frame. Normally only used internally via sendMessage(), sendPing(), sendPong() and sendClose().

This method deliberately allows to send invalid frames (that is frames invalid per-se, or frames invalid because of protocol state). Other than in fuzzing servers, calling methods will ensure that no invalid frames are sent.

In addition, this method supports explicit specification of payload length. When payload_len is given, it will always write that many octets to the stream. It’ll wrap within payload, resending parts of that when more octets were requested The use case is again for fuzzing server which want to sent increasing amounts of payload data to peers without having to construct potentially large messages themselves.

Modes: Hybi

sendPing(payload=None)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.sendPing()

sendPong(payload=None)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.sendPong()

sendCloseFrame(code=None, reasonUtf8=None, isReply=False)[source]

Send a close frame and update protocol state. Note, that this is an internal method which deliberately allows not send close frame with invalid payload.

Modes: Hybi, Hixie

Notes:
  • For Hixie mode, this method is slightly misnamed for historic reasons.
  • For Hixie mode, code and reasonUtf8 will be silently ignored.
sendClose(code=None, reason=None)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.sendClose()

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

Implements autobahn.websocket.interfaces.IWebSocketChannel.beginMessage()

beginMessageFrame(length)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.beginMessageFrame()

sendMessageFrameData(payload, sync=False)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.sendMessageFrameData()

endMessage()[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.endMessage()

sendMessageFrame(payload, sync=False)[source]

Implements autobahn.websocket.interfaces.IWebSocketChannel.sendMessageFrame()

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

Implements autobahn.websocket.interfaces.IWebSocketChannel.sendMessage()

sendMessageHixie76(payload, sync=False)[source]

Hixie76-Variant of sendMessage().

Modes: Hixie

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

Hybi-Variant of sendMessage().

Modes: Hybi

class autobahn.websocket.protocol.WebSocketFactory[source]

Mixin for autobahn.websocket.protocol.WebSocketClientFactory and autobahn.websocket.protocol.WebSocketServerFactory.

prepareMessage(payload, isBinary=False, doNotCompress=False)[source]

Prepare a WebSocket message. This can be later sent on multiple instances of autobahn.websocket.WebSocketProtocol using autobahn.websocket.WebSocketProtocol.sendPreparedMessage().

By doing so, you can avoid the (small) overhead of framing the same payload into WebSocket messages multiple times when that same payload is to be sent out on multiple connections.

Parameters:
  • payload (bytes) – The message payload.
  • isBinary (bool) – True iff payload is binary, else the payload must be UTF-8 encoded text.
  • 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).
Returns:

obj – An instance of autobahn.websocket.protocol.PreparedMessage.

class autobahn.websocket.protocol.WebSocketServerProtocol[source]

Bases: autobahn.websocket.protocol.WebSocketProtocol

Protocol base class for WebSocket servers.

CONFIG_ATTRS = ['debug', 'debugCodePaths', 'logOctets', 'logFrames', 'trackTimings', 'allowHixie76', 'utf8validateIncoming', 'applyMask', 'maxFramePayloadSize', 'maxMessagePayloadSize', 'autoFragmentSize', 'failByDrop', 'echoCloseCodeReason', 'openHandshakeTimeout', 'closeHandshakeTimeout', 'tcpNoDelay', 'autoPingInterval', 'autoPingTimeout', 'autoPingSize', 'versions', 'webStatus', 'requireMaskedClientFrames', 'maskServerFrames', 'perMessageCompressionAccept', 'serveFlashSocketPolicy', 'flashSocketPolicy', 'allowedOrigins', 'allowedOriginsPatterns']
onConnect(request)[source]

Callback fired during WebSocket opening handshake when new WebSocket client connection is about to be established.

When you want to accept the connection, return the accepted protocol from list of WebSocket (sub)protocols provided by client or None to speak no specific one or when the client protocol list was empty.

You may also return a pair of (protocol, headers) to send additional HTTP headers, with headers being a dictionary of key-values.

Throw autobahn.websocket.http.HttpException when you don’t want to accept the WebSocket connection request.

Parameters:request (instance of autobahn.websocket.protocol.ConnectionRequest) – WebSocket connection request information.
processProxyConnect()[source]
parseHixie76Key(key)[source]

Parse Hixie76 opening handshake key provided by client.

processHandshake()[source]

Process WebSocket opening handshake request from client.

succeedHandshake(res)[source]

Callback after onConnect() returns successfully. Generates the response for the handshake.

failHandshake(reason, code=400, responseHeaders=None)[source]

During opening handshake the client request was invalid, we send a HTTP error response and then drop the connection.

sendHttpErrorResponse(code, reason, responseHeaders=None)[source]

Send out HTTP error response.

sendHtml(html)[source]

Send HTML page HTTP response.

sendRedirect(url)[source]

Send HTTP Redirect (303) response.

sendServerStatus(redirectUrl=None, redirectAfter=0)[source]

Used to send out server status/version upon receiving a HTTP/GET without upgrade to WebSocket header (and option serverStatus is True).

class autobahn.websocket.protocol.WebSocketServerFactory(url=None, protocols=None, server='AutobahnPython/0.9.4', headers=None, externalPort=None, debug=False, debugCodePaths=False)[source]

Bases: autobahn.websocket.protocol.WebSocketFactory

A protocol factory for WebSocket servers.

Create instance of WebSocket server factory.

Parameters:
  • url (str) – The WebSocket URL this factory is working for, e.g. ws://myhost.com/somepath. For non-TCP transports like pipes or Unix domain sockets, provide None. This will use an implicit URL of ws://localhost.
  • protocols (list of strings) – List of subprotocols the server supports. The subprotocol used is the first from the list of subprotocols announced by the client that is contained in this list.
  • server (str) – Server as announced in HTTP response header during opening handshake or None (default: AutobahnWebSocket/?.?.?).
  • headers (dict) – An optional mapping of additional HTTP headers to send during the WebSocket opening handshake.
  • externalPort (int) – Optionally, the external visible port this factory will be reachable under (i.e. when running behind a L2/L3 forwarding device).
  • debug (bool) – Debug mode (default: False).
  • debugCodePaths (bool) – Debug code paths mode (default: False).
protocol

The protocol to be spoken. Must be derived from autobahn.websocket.protocol.WebSocketServerProtocol.

alias of WebSocketServerProtocol

isServer = True

Flag indicating if this factory is client- or server-side.

setSessionParameters(url=None, protocols=None, server=None, headers=None, externalPort=None)[source]

Set WebSocket session parameters.

Parameters:
  • url (str) – The WebSocket URL this factory is working for, e.g. ws://myhost.com/somepath. For non-TCP transports like pipes or Unix domain sockets, provide None. This will use an implicit URL of ws://localhost.
  • protocols (list of strings) – List of subprotocols the server supports. The subprotocol used is the first from the list of subprotocols announced by the client that is contained in this list.
  • server (str) – Server as announced in HTTP response header during opening handshake.
  • headers (dict) – An optional mapping of additional HTTP headers to send during the WebSocket opening handshake.
  • externalPort (int) – Optionally, the external visible port this server will be reachable under (i.e. when running behind a L2/L3 forwarding device).
resetProtocolOptions()[source]

Reset all WebSocket protocol options to defaults.

setProtocolOptions(versions=None, allowHixie76=None, webStatus=None, utf8validateIncoming=None, maskServerFrames=None, requireMaskedClientFrames=None, applyMask=None, maxFramePayloadSize=None, maxMessagePayloadSize=None, autoFragmentSize=None, failByDrop=None, echoCloseCodeReason=None, openHandshakeTimeout=None, closeHandshakeTimeout=None, tcpNoDelay=None, perMessageCompressionAccept=None, autoPingInterval=None, autoPingTimeout=None, autoPingSize=None, serveFlashSocketPolicy=None, flashSocketPolicy=None, allowedOrigins=None)[source]

Set WebSocket protocol options used as defaults for new protocol instances.

Parameters:
  • versions (list of ints or None) – The WebSocket protocol versions accepted by the server (default: autobahn.websocket.protocol.WebSocketProtocol.SUPPORTED_PROTOCOL_VERSIONS()).
  • allowHixie76 (bool or None) – Allow to speak Hixie76 protocol version.
  • webStatus (bool or None) – Return server status/version on HTTP/GET without WebSocket upgrade header (default: True).
  • utf8validateIncoming (bool or None) – Validate incoming UTF-8 in text message payloads (default: True).
  • maskServerFrames (bool or None) – Mask server-to-client frames (default: False).
  • requireMaskedClientFrames (bool or None) – Require client-to-server frames to be masked (default: True).
  • applyMask (bool or None) – Actually apply mask to payload when mask it present. Applies for outgoing and incoming frames (default: True).
  • maxFramePayloadSize (int or None) – Maximum frame payload size that will be accepted when receiving or 0 for unlimited (default: 0).
  • maxMessagePayloadSize (int or None) – Maximum message payload size (after reassembly of fragmented messages) that will be accepted when receiving or 0 for unlimited (default: 0).
  • autoFragmentSize (int or None) – Automatic fragmentation of outgoing data messages (when using the message-based API) into frames with payload length <= this size or 0 for no auto-fragmentation (default: 0).
  • failByDrop – Fail connections by dropping the TCP connection without performing closing handshake (default: True).
  • echoCloseCodeReason (bool or None) – Iff true, when receiving a close, echo back close code/reason. Otherwise reply with code == 1000, reason = “” (default: False).
  • openHandshakeTimeout (float or None) – Opening WebSocket handshake timeout, timeout in seconds or 0 to deactivate (default: 0).
  • closeHandshakeTimeout (float or None) – When we expect to receive a closing handshake reply, timeout in seconds (default: 1).
  • tcpNoDelay (bool or None) – TCP NODELAY (“Nagle”) socket option (default: True).
  • perMessageCompressionAccept (callable or None) – Acceptor function for offers.
  • autoPingInterval (float or None) – Automatically send WebSocket pings every given seconds. When the peer does not respond in autoPingTimeout, drop the connection. Set to 0 to disable. (default: 0).
  • autoPingTimeout (float or None) – Wait this many seconds for the peer to respond to automatically sent pings. If the peer does not respond in time, drop the connection. Set to 0 to disable. (default: 0).
  • autoPingSize (int or None) – Payload size for automatic pings/pongs. Must be an integer from [4, 125]. (default: 4).
  • serveFlashSocketPolicy (bool or None) – Serve the Flash Socket Policy when we receive a policy file request on this protocol. (default: False).
  • flashSocketPolicy (str or None) – The flash socket policy to be served when we are serving the Flash Socket Policy on this protocol and when Flash tried to connect to the destination port. It must end with a null character.
  • allowedOrigins (list or None) – A list of allowed WebSocket origins (with ‘*’ as a wildcard character).
getConnectionCount()[source]

Get number of currently connected clients.

Returns:int – Number of currently connected clients.
class autobahn.websocket.protocol.WebSocketClientProtocol[source]

Bases: autobahn.websocket.protocol.WebSocketProtocol

Protocol base class for WebSocket clients.

CONFIG_ATTRS = ['debug', 'debugCodePaths', 'logOctets', 'logFrames', 'trackTimings', 'allowHixie76', 'utf8validateIncoming', 'applyMask', 'maxFramePayloadSize', 'maxMessagePayloadSize', 'autoFragmentSize', 'failByDrop', 'echoCloseCodeReason', 'openHandshakeTimeout', 'closeHandshakeTimeout', 'tcpNoDelay', 'autoPingInterval', 'autoPingTimeout', 'autoPingSize', 'version', 'acceptMaskedServerFrames', 'maskClientFrames', 'serverConnectionDropTimeout', 'perMessageCompressionOffers', 'perMessageCompressionAccept']
onConnect(response)[source]

Callback fired directly after WebSocket opening handshake when new WebSocket server connection was established.

Parameters:response (instance of autobahn.websocket.protocol.ConnectionResponse) – WebSocket connection response information.
startProxyConnect()[source]

Connect to explicit proxy.

processProxyConnect()[source]

Process HTTP/CONNECT response from server.

failProxyConnect(reason)[source]

During initial explicit proxy connect, the server response indicates some failure and we drop the connection.

createHixieKey()[source]

Implements this algorithm:

http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76#page-21 Items 16 - 22

startHandshake()[source]

Start WebSocket opening handshake.

processHandshake()[source]

Process WebSocket opening handshake response from server.

failHandshake(reason)[source]

During opening handshake the server response is invalid and we drop the connection.

class autobahn.websocket.protocol.WebSocketClientFactory(url=None, origin=None, protocols=None, useragent='AutobahnPython/0.9.4', headers=None, proxy=None, debug=False, debugCodePaths=False)[source]

Bases: autobahn.websocket.protocol.WebSocketFactory

A protocol factory for WebSocket clients.

Create instance of WebSocket client factory.

Note that you MUST provide URL either here or set using autobahn.websocket.WebSocketClientFactory.setSessionParameters() before the factory is started.

Parameters:
  • url (str) – WebSocket URL this factory will connect to, e.g. ws://myhost.com/somepath?param1=23. For non-TCP transports like pipes or Unix domain sockets, provide None. This will use an implicit URL of ws://localhost.
  • origin (str) – The origin to be sent in WebSocket opening handshake or None (default: None).
  • protocols (list of strings) – List of subprotocols the client should announce in WebSocket opening handshake (default: []).
  • useragent (str) – User agent as announced in HTTP request header or None (default: AutobahnWebSocket/?.?.?).
  • headers (dict) – An optional mapping of additional HTTP headers to send during the WebSocket opening handshake.
  • proxy (str) – Explicit proxy server to use (hostname:port or IP:port), e.g. 192.168.1.100:8080.
  • debug (bool) – Debug mode (default: False).
  • debugCodePaths (bool) – Debug code paths mode (default: False).
protocol

The protocol to be spoken. Must be derived from autobahn.websocket.protocol.WebSocketClientProtocol.

alias of WebSocketClientProtocol

isServer = False

Flag indicating if this factory is client- or server-side.

setSessionParameters(url=None, origin=None, protocols=None, useragent=None, headers=None, proxy=None)[source]

Set WebSocket session parameters.

Parameters:
  • url (str) – WebSocket URL this factory will connect to, e.g. ws://myhost.com/somepath?param1=23. For non-TCP transports like pipes or Unix domain sockets, provide None. This will use an implicit URL of ws://localhost.
  • origin (str) – The origin to be sent in opening handshake.
  • protocols (list of strings) – List of WebSocket subprotocols the client should announce in opening handshake.
  • useragent (str) – User agent as announced in HTTP request header during opening handshake.
  • headers (dict) – An optional mapping of additional HTTP headers to send during the WebSocket opening handshake.
resetProtocolOptions()[source]

Reset all WebSocket protocol options to defaults.

setProtocolOptions(version=None, allowHixie76=None, utf8validateIncoming=None, acceptMaskedServerFrames=None, maskClientFrames=None, applyMask=None, maxFramePayloadSize=None, maxMessagePayloadSize=None, autoFragmentSize=None, failByDrop=None, echoCloseCodeReason=None, serverConnectionDropTimeout=None, openHandshakeTimeout=None, closeHandshakeTimeout=None, tcpNoDelay=None, perMessageCompressionOffers=None, perMessageCompressionAccept=None, autoPingInterval=None, autoPingTimeout=None, autoPingSize=None)[source]

Set WebSocket protocol options used as defaults for _new_ protocol instances.

Parameters:
  • version – The WebSocket protocol spec (draft) version to be used (default: autobahn.websocket.protocol.WebSocketProtocol.SUPPORTED_PROTOCOL_VERSIONS()).
  • utf8validateIncoming (bool) – Validate incoming UTF-8 in text message payloads (default: True).
  • acceptMaskedServerFrames (bool) – Accept masked server-to-client frames (default: False).
  • maskClientFrames (bool) – Mask client-to-server frames (default: True).
  • applyMask (bool) – Actually apply mask to payload when mask it present. Applies for outgoing and incoming frames (default: True).
  • maxFramePayloadSize (int) – Maximum frame payload size that will be accepted when receiving or 0 for unlimited (default: 0).
  • maxMessagePayloadSize (int) – Maximum message payload size (after reassembly of fragmented messages) that will be accepted when receiving or 0 for unlimited (default: 0).
  • autoFragmentSize (int) – Automatic fragmentation of outgoing data messages (when using the message-based API) into frames with payload length <= this size or 0 for no auto-fragmentation (default: 0).
  • failByDrop – Fail connections by dropping the TCP connection without performing closing handshake (default: True).
  • echoCloseCodeReason (bool) – Iff true, when receiving a close, echo back close code/reason. Otherwise reply with code == 1000, reason = “” (default: False).
  • serverConnectionDropTimeout (float) – When the client expects the server to drop the TCP, timeout in seconds (default: 1).
  • openHandshakeTimeout (float) – Opening WebSocket handshake timeout, timeout in seconds or 0 to deactivate (default: 0).
  • closeHandshakeTimeout (float) – When we expect to receive a closing handshake reply, timeout in seconds (default: 1).
  • tcpNoDelay (bool) – TCP NODELAY (“Nagle”): bool socket option (default: True).
  • perMessageCompressionOffers (list of instance of subclass of PerMessageCompressOffer) – A list of offers to provide to the server for the permessage-compress WebSocket extension. Must be a list of instances of subclass of PerMessageCompressOffer.
  • perMessageCompressionAccept (callable) – Acceptor function for responses.
  • autoPingInterval (float or None) – Automatically send WebSocket pings every given seconds. When the peer does not respond in autoPingTimeout, drop the connection. Set to 0 to disable. (default: 0).
  • autoPingTimeout (float or None) – Wait this many seconds for the peer to respond to automatically sent pings. If the peer does not respond in time, drop the connection. Set to 0 to disable. (default: 0).
  • autoPingSize (int) – Payload size for automatic pings/pongs. Must be an integer from [4, 125]. (default: 4).

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[source]

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()[source]

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()[source]

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

validate()[source]

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