Skip to content

telnet

Wrapper around telnetlib.

from pathfinder.telnet import TelnetClient tc = TelnetClient() tc.connect() tc.disconnect()

TelnetClient

Telnet client handler.

Source code in pathfinder/telnet.py
class TelnetClient:
    """Telnet client handler."""

    config = {"host": "localhost", "port": 9600, "timeout": 1}

    def __init__(self, config={}):
        self.config = {**self.config, **config}
        self.client = telnetlib.Telnet()

    def connect(self):
        """Connect the client."""
        try:
            self.client.open(
                self.config.get("host"),
                self.config.get("port"),
                self.config.get("timeout"),
            )
        except Exception as ex:
            logger.error("Error connecting telnet client")
            raise TelnetClientException(ex)

    def disconnect(self):
        """Disconnect the client."""
        try:
            self.client.close()
        except Exception as ex:
            logger.error("Error disconnecting telnet client")
            raise TelnetClientException(ex)

connect()

Connect the client.

Source code in pathfinder/telnet.py
def connect(self):
    """Connect the client."""
    try:
        self.client.open(
            self.config.get("host"),
            self.config.get("port"),
            self.config.get("timeout"),
        )
    except Exception as ex:
        logger.error("Error connecting telnet client")
        raise TelnetClientException(ex)

disconnect()

Disconnect the client.

Source code in pathfinder/telnet.py
def disconnect(self):
    """Disconnect the client."""
    try:
        self.client.close()
    except Exception as ex:
        logger.error("Error disconnecting telnet client")
        raise TelnetClientException(ex)

TelnetClientException

Bases: Exception

Exceptions raised by TelnetClient.

Source code in pathfinder/telnet.py
class TelnetClientException(Exception):
    """Exceptions raised by TelnetClient."""

    pass