hvl_ccb.comm.telnet
Communication protocol for telnet. Makes use of the telnetlib library.
- class TelnetCommunication(configuration)[source]
Bases:
AsyncCommunicationProtocol
Implements the Communication Protocol for telnet.
- static config_cls()[source]
Return the default configdataclass class.
- Returns
a reference to the default configdataclass class
- property is_open: bool
Is the connection open?
- Returns
True for an open connection
- read_bytes() bytes [source]
Read data as bytes from the telnet connection.
- Returns
data from telnet connection
- Raises
TelnetError – when connection is not open, raises an Error during the communication
- write_bytes(data: bytes)[source]
Write the data as bytes to the telnet connection.
- Parameters
data – Data to be sent.
- Raises
TelnetError – when connection is not open, raises an Error during the communication
- class TelnetCommunicationConfig(terminator: bytes = b'\r\n', encoding: str = 'utf-8', encoding_error_handling: str = 'strict', wait_sec_read_text_nonempty: Union[int, float] = 0.5, default_n_attempts_read_text_nonempty: int = 10, host: Optional[Union[str, IPv4Address, IPv6Address]] = None, port: int = 0, timeout: Union[int, float] = 0.2)[source]
Bases:
AsyncCommunicationProtocolConfig
Configuration dataclass for
TelnetCommunication
.- create_telnet() Optional[Telnet] [source]
Create a telnet client :return: Opened Telnet object or None if connection is not possible
- force_value(fieldname, value)
Forces a value to a dataclass field despite the class being frozen.
NOTE: you can define post_force_value method with same signature as this method to do extra processing after value has been forced on fieldname.
- Parameters
fieldname – name of the field
value – value to assign
- host: Optional[Union[str, IPv4Address, IPv6Address]] = None
Host to connect to can be
localhost
or
- classmethod keys() Sequence[str]
Returns a list of all configdataclass fields key-names.
- Returns
a list of strings containing all keys.
- classmethod optional_defaults() Dict[str, object]
Returns a list of all configdataclass fields, that have a default value assigned and may be optionally specified on instantiation.
- Returns
a list of strings containing all optional keys.
- port: int = 0
Port at which the host is listening
- classmethod required_keys() Sequence[str]
Returns a list of all configdataclass fields, that have no default value assigned and need to be specified on instantiation.
- Returns
a list of strings containing all required keys.
- timeout: Union[int, float] = 0.2
Timeout for reading a line
- exception TelnetError[source]
Bases:
OSError
,CommunicationError
Telnet communication related errors.