unicon.eal.backend package

Submodules

unicon.eal.backend.pty_backend module

Module:

unicon.eal.backend.pty_backend

Authors:

ATS TEAM (ats-dev@cisco.com, CSG(STEP) - India)

Description:

Spawn class is used to invoke commands with which we need to interact. It provides methods for interacting with the spawned commands by using methods like send/expect. It is very similar in intent as Tcl/Expect’s spawn command.

class unicon.eal.backend.pty_backend.RawPtySpawn(*args, **kwargs)

Bases: unicon.eal.backend.pty_backend.RawSpawn

This class adds pty-specific spawn logic .

close()
is_readable(timeout=0.01)
is_writable(timeout=0.01)
class unicon.eal.backend.pty_backend.RawSpawn(spawn_command, target=None, size=None, timeout=None, logger=<Logger unicon.eal.backend.pty_backend (WARNING)>, invoke_shell_timeout=None, settings=<unicon.settings.Settings object>, match_mode_detect=None, **kwargs)

Bases: unicon.eal.bases.BaseSpawn

This class contains most of the generic spawn logic.

close()
expect(patterns, timeout=None, size=None, trim_buffer=True, search_size=None, log_timeout=True)

match a list of patterns against the buffer

expect takes a list of patterns and matches it against the content of the buffer. After any one of the patterns matches, in the user provided list, it trims the buffer till that match. The buffer contains the remaining data in an anticipation that it will be used in the expect call for matching.

However sometime it may be useful to maintain the buffer as it is, even after the match has happened. This is equivalent to the no_transfer feature in the Tcl/Expect. To achieve that effect trim_buffer can be set to False, which is True by default.

Parameters
  • patterns – list of patterns.

  • timeout – time to wait for any of the patterns to match.

  • size – read size in bytes for reading the buffer.

  • trim_buffer – whether to trim the buffer after a successful match.

  • search_size – maximum size in bytes to search at the end of the buffer

  • log_timeout – whether to log Timeout info when no pattern is matched

Example

e.sendline("a command")
e.expect([r'^pat1', r'pat2'], timeout=10)
Returns

ExpectMatch instance. * It contains the index of the pattern that matched. * matched string. * re match object.

Raises

TimeoutError – In case no match is found within the timeout period.

property has_buffer_left
is_readable(timeout=0.01)
is_writable(timeout=0.01)
match_buffer(pat_list, search_size=None)

Match regex patterns against the buffer. Rules as below:

  1. search whole buffer with re.DOTALL if:

  • pattern contains any of: \r, \n

  • pattern equals to any of: .*, ^.*$, .*$, ^.*, .+, ^.+$, .+$, ^.+

  1. If pattern ends with $ but not $, will only match last line

  2. In other situations, search whole buffer with re.DOTALL

Parameters
  • pat_list – list of regex patterns.

  • search_size – maximum size in bytes to search at the end of the buffer.

Returns

index of pattern list or False if no match

read(size=None)
read_update_buffer(size=None)

perform a single read and update buffer content

send(command, *args, **kwargs)
sendline(command=None)
trim_buffer()

trims the buffer based on match object

class unicon.eal.backend.pty_backend.Spawn(*args, hostname=None, **kwargs)

Bases: unicon.eal.backend.pty_backend.RawPtySpawn

This class adds hostname logic.

Module contents