ATS TEAM (email@example.com, CSG(STEP) - India)
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)¶
This class adds pty-specific spawn logic .
- 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)¶
This class contains most of the generic spawn logic.
- 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.
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
e.sendline("a command") e.expect([r'^pat1', r'pat2'], timeout=10)
ExpectMatch instance. * It contains the index of the pattern that matched. * matched string. * re match object.
TimeoutError – In case no match is found within the timeout period.
- property has_buffer_left¶
- match_buffer(pat_list, search_size=None)¶
Match regex patterns against the buffer. Rules as below:
search whole buffer with re.DOTALL if:
pattern contains any of: \r, \n
pattern equals to any of: .*, ^.*$, .*$, ^.*, .+, ^.+$, .+$, ^.+
If pattern ends with $ but not $, will only match last line
In other situations, search whole buffer with re.DOTALL
pat_list – list of regex patterns.
search_size – maximum size in bytes to search at the end of the buffer.
index of pattern list or False if no match
perform a single read and update buffer content
- send(command, *args, **kwargs)¶
trims the buffer based on match object