whisker.twistedclient

whisker/twistedclient.py


Copyright © 2011-2020 Rudolf Cardinal (rudolf@pobox.com).

This file is part of the Whisker Python client library.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Event-driven framework for Whisker Python clients using Twisted.

  • Created: 18 Aug 2011

  • Last update: 10 Feb 2016

class whisker.twistedclient.WhiskerImmSocket(task: WhiskerTwistedTask)[source]

Whisker Twisted immediate socket handler.

Uses raw sockets.

Parameters:

task – instance of WhiskerTwistedTask

connect(server: str, port: int) None[source]

Connects the Whisker immediate socket.

Parameters:
  • server – server hostname/IP address

  • port – immediate port number

getlines_immsock() Generator[str, None, None][source]

Generates lines from the immediate socket.

Yields:

lines from the socket

send_and_get_reply(*args) str[source]

Builds its arguments into a string; sends it to Whisker via the immediate socket; gets the reply; returns it.

class whisker.twistedclient.WhiskerMainPortFactory(task: WhiskerTwistedTask)[source]

A Protocol factory for the Whisker main port.

Parameters:

task – instance of WhiskerTwistedTask

buildProtocol(addr: str) WhiskerMainPortProtocol | None[source]

Build and return the protocol.

clientConnectionFailed(connector: Connector, reason: str) None[source]

Client connection failed. Stop the reactor.

clientConnectionLost(connector: Connector, reason: str) None[source]

If we get disconnected, reconnect to server.

class whisker.twistedclient.WhiskerMainPortProtocol(task: WhiskerTwistedTask, encoding: str = 'ascii')[source]

Line-based Twisted protocol for the Whisker main port.

Parameters:
connectionMade() None[source]

Called when the main port is connected.

lineReceived(data: bytes) None[source]

Called when data is received on the main port. Sends it to WhiskerTwistedTask.incoming_message() via self.task.

Parameters:

data – bytes

rawDataReceived(data: bytes) None[source]

Raw data received. Unused; we use lineReceived() instead.

send(data: str) None[source]

Encodes and sends data to the main port.

class whisker.twistedclient.WhiskerTwistedTask[source]

Base class for Whisker clients using the Twisted socket system.

connect(server: str, port: str | int) None[source]

Connects to the Whisker server.

Parameters:
  • server – Whisker server hostname/IP address

  • port – Whisker main TCP/IP port number

fully_connected() None[source]

The Whisker server is now fully connected.

Override this, e.g. to start the task.

incoming_client_message(fromclientnum: int, msg: str, timestamp: int | None = None) None[source]

Client message (from another client) received.

Override this function.

Parameters:
  • fromclientnum – source client number

  • msg – message

  • timestamp – server timestamp (ms)

incoming_error(msg: str) None[source]

Error report received from Whisker server.

Parameters:

msg – message

incoming_event(event: str, timestamp: int | None = None) None[source]

General Whisker event received.

Override this function.

Parameters:
  • event – event

  • timestamp – server timestamp (ms)

incoming_info(msg: str) None[source]

Information message received from Whisker server.

Parameters:

msg – message

incoming_key_event(key: str, depressed: bool, document: str, timestamp: int | None = None) None[source]

Keyboard event received.

Override this function.

Parameters:
  • key – which key?

  • depressed – was it depressed (or released)?

  • document – source display document

  • timestamp – server timestamp (ms)

incoming_message(msg: str) None[source]

Processes an incoming message from the Whisker server (via the main socket).

incoming_syntax_error(msg: str) None[source]

Syntax error report received from Whisker server.

Parameters:

msg – message

incoming_warning(msg: str) None[source]

Warning received from Whisker server.

Parameters:

msg – message

send(*args) None[source]

Builds its arguments into a string and sends that as a command to the Whisker server via the main socket.

send_and_get_reply(*args) str | None[source]

Builds its arguments into a string, sends that as a command to the Whisker server via the immediate socket, blocks and waits for the reply, and returns that reply. (Returns None if not connected.)

classmethod set_verbose_logging(verbose: bool) None[source]

Sets the Python log level for this module.

Parameters:

verbose – be verbose?