Exscript.servers.server module

Base class for all servers.

class Exscript.servers.server.Server(host, port, device, encoding='utf8')[source]

Bases: multiprocessing.process.Process

Base class of the Telnet and SSH servers. Servers are intended to be used for tests and attempt to emulate a device using the behavior of the associated Exscript.emulators.VirtualDevice. Sample usage:

device = VirtualDevice('myhost')
daemon = Telnetd('localhost', 1234, device)
device.add_command('ls', 'ok', prompt = True)
device.add_command('exit', daemon.exit_command)
daemon.start() # Start the server.
daemon.exit()  # Stop the server.
daemon.join()  # Wait until it terminates.
__init__(host, port, device, encoding='utf8')[source]

Constructor.

Parameters:
  • host (str) – The address against which the daemon binds.
  • port (str) – The TCP port on which to listen.
  • device (VirtualDevice) – A virtual device instance.
  • encoding (str) – The encoding of data between client and server.
exit()[source]

Stop the daemon without waiting for the thread to terminate.

exit_command(cmd)[source]

Like exit(), but may be used as a handler in add_command.

Parameters:cmd (str) – The command that causes the server to exit.