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
- 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.
- class whisker.twistedclient.WhiskerMainPortProtocol(task: WhiskerTwistedTask, encoding: str = 'ascii')[source]
Line-based Twisted protocol for the Whisker main port.
- Parameters:
task – instance of
WhiskerTwistedTask
encoding – encoding to use; normally
"ascii"
- lineReceived(data: bytes) None [source]
Called when data is received on the main port. Sends it to
WhiskerTwistedTask.incoming_message()
viaself.task
.- Parameters:
data – bytes
- rawDataReceived(data: bytes) None [source]
Raw data received. Unused; we use
lineReceived()
instead.
- class whisker.twistedclient.WhiskerTwistedTask[source]
Base class for Whisker clients using the Twisted socket system.
Contains
self.whisker
, an instance ofwhisker.api.WhiskerApi
.Specimen usage: see
test_twisted.py
.
- 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.