client_base

Module provides class BaseClient.

class BaseClient(shell=None, encoding='utf8', encoding_errors='strict', force_binary=False, connect_minwait=1.0, connect_maxwait=4.0, limit=None, waiter_closed=None, _waiter_connected=None)[source]

Bases: asyncio.streams.FlowControlMixin, asyncio.protocols.Protocol

Base Telnet Client Protocol.

Class initializer.

default_encoding = None

encoding for new connections

connect_minwait = None

minimum duration for check_negotiation().

connect_maxwait = None

maximum duration for check_negotiation().

eof_received()[source]

Called when the other end calls write_eof() or equivalent.

connection_lost(exc)[source]

Called when the connection is lost or closed.

Parameters:exc (Exception) – exception. None indicates a closing EOF sent by this end.
connection_made(transport)[source]

Called when a connection is made.

Ensure super().connection_made(transport) is called when derived.

begin_shell(result)[source]
data_received(data)[source]

Process bytes received by transport.

duration

Time elapsed since client connected, in seconds as float.

idle

Time elapsed since data last received, in seconds as float.

get_extra_info(name, default=None)[source]

Get optional client protocol or transport information.

begin_negotiation()[source]

Begin on-connect negotiation.

A Telnet client is expected to send only a minimal amount of client session options immediately after connection, it is generally the server which dictates server option support.

Deriving implementations should always call super().begin_negotiation().

encoding(outgoing=False, incoming=False)[source]

Encoding that should be used for the direction indicated.

The base implementation always returns encoding argument given to class initializer or, when unset (None), US-ASCII.

check_negotiation(final=False)[source]

Callback, return whether negotiation is complete.

Parameters:final (bool) – Whether this is the final time this callback will be requested to answer regarding protocol negotiation.
Returns:Whether negotiation is over (client end is satisfied).
Return type:bool

Method is called on each new command byte processed until negotiation is considered final, or after connect_maxwait has elapsed, setting the _waiter_connected attribute to value self when complete.

This method returns False until connect_minwait has elapsed, ensuring the server may batch telnet negotiation demands without prematurely entering the callback shell.

Ensure super().check_negotiation() is called and conditionally combined when derived.

pause_writing()

Called when the transport’s buffer goes over the high-water mark.

Pause and resume calls are paired – pause_writing() is called once when the buffer goes strictly over the high-water mark (even if subsequent writes increases the buffer size even more), and eventually resume_writing() is called once when the buffer size reaches the low-water mark.

Note that if the buffer size equals the high-water mark, pause_writing() is not called – it must go strictly over. Conversely, resume_writing() is called when the buffer size is equal or lower than the low-water mark. These end conditions are important to ensure that things go as expected when either mark is zero.

NOTE: This is the only Protocol callback that is not called through EventLoop.call_soon() – if it were, it would have no effect when it’s most needed (when the app keeps writing without yielding until pause_writing() is called).

resume_writing()

Called when the transport’s buffer drains below the low-water mark.

See pause_writing() for details.