autobahn.websocket.util


Module Contents

Functions

create_url(hostname[, port, isSecure, path, params])

Create a WebSocket URL from components.

parse_url(url)

Parses as WebSocket URL into it's components and returns a tuple:

autobahn.websocket.util.create_url(hostname, port=None, isSecure=False, path=None, params=None)[source]

Create a WebSocket URL from components.

Parameters
  • hostname (str) – WebSocket server hostname (for TCP/IP sockets) or filesystem path (for Unix domain sockets).

  • port (int or str) – For TCP/IP sockets, WebSocket service port or None (to select default ports 80 or 443 depending on isSecure. When hostname=="unix", this defines the path to the Unix domain socket instead of a TCP/IP network socket.

  • isSecure (bool) – Set True for secure WebSocket (wss scheme).

  • path (str) – WebSocket URL path of addressed resource (will be properly URL escaped). Ignored for RawSocket.

  • params (dict) – A dictionary of key-values to construct the query component of the addressed WebSocket resource (will be properly URL escaped). Ignored for RawSocket.

Returns

Constructed WebSocket URL.

Return type

str

autobahn.websocket.util.parse_url(url)[source]

Parses as WebSocket URL into it’s components and returns a tuple:

  • isSecure is a flag which is True for wss URLs.

  • host is the hostname or IP from the URL.

and for TCP/IP sockets:

  • tcp_port is the port from the URL or standard port derived from scheme (rs => 80, rss => 443).

or for Unix domain sockets:

  • uds_path is the path on the local host filesystem.

Parameters

url (str) – A valid WebSocket URL, i.e. ws://localhost:9000 for TCP/IP sockets or ws://unix:/tmp/file.sock for Unix domain sockets (UDS).

Returns

A 6-tuple (isSecure, host, tcp_port, resource, path, params) (TCP/IP) or (isSecure, host, uds_path, resource, path, params) (UDS).

Return type

tuple