pants.contrib.telnet

Constants

Telnet Commands:
 
Constant Value
IAC '\xFF'
DONT '\xFE'
DO '\xFD'
WONT '\xFC'
WILL '\xFB'
SB '\xFA'
SE '\xF0'

TelnetConnection

class pants.contrib.telnet.TelnetConnection(**kwargs)[source]

A basic implementation of a Telnet connection.

A TelnetConnection object is capable of identifying and extracting Telnet command sequences from incoming data. Upon identifying a Telnet command, option or subnegotiation, the connection will call a relevant placeholder method. This class should be subclassed to provide functionality for individual commands and options.

close(flush=True)

Close the channel.

on_close()

Placeholder. Called after the channel has finished closing.

on_command(command)[source]

Placeholder. Called when the connection receives a telnet command, such as AYT (Are You There).

Argument Description
command The byte representing the telnet command.
on_connect()

Placeholder. Called after the channel has connected to a remote socket.

on_option(command, option)[source]

Placeholder. Called when the connection receives a telnet option negotiation sequence, such as IAC WILL ECHO.

Argument Description
command The byte representing the telnet command.
option The byte representing the telnet option being negotiated.
on_read(data)

Placeholder. Called when data is read from the channel.

Argument Description
data A chunk of data received from the socket.
on_subnegotiation(option, data)[source]

Placeholder. Called when the connection receives a subnegotiation sequence.

Argument Description
option The byte representing the telnet option for which subnegotiation data has been received.
data The received data.
on_write()

Placeholder. Called after the channel has finished writing data.

write(data, flush=False)

Write data to the channel.

Data will not be written immediately, but will be buffered internally until it can be sent without blocking the process.

Calling write() on a closed or disconnected channel will raise a RuntimeError.

Arguments Description
data A string of data to write to the channel.
flush Optional. If True, flush the internal write buffer. See flush() for details.
write_file(sfile, nbytes=0, offset=0, flush=False)

Write a file to the channel.

The file will not be written immediately, but will be buffered internally until it can be sent without blocking the process.

Calling write_file() on a closed or disconnected channel will raise a RuntimeError.

Arguments Description
sfile A file object to write to the channel.
nbytes Optional. The number of bytes of the file to write. If 0, all bytes will be written.
offset Optional. The number of bytes to offset writing by.
flush Optional. If True, flush the internal write buffer. See flush() for details.

TelnetServer

class pants.contrib.telnet.TelnetServer(ConnectionClass=None, **kwargs)[source]

A basic implementation of a Telnet server.