Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions plugins/connection/network_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@
HAS_SCP = False
display = Display()

REGEX_MAX_LENGTH = 1024


def ensure_connect(func):
@wraps(func)
Expand Down Expand Up @@ -1092,7 +1094,7 @@ def _handle_prompt(
"Prompts provided: %s" % (to_text(exc), prompts)
)
for index, regex in enumerate(prompts_regex):
match = regex.search(resp)
match = regex.search(resp[-REGEX_MAX_LENGTH:])
if match:
self._matched_cmd_prompt = match.group()
self._log_messages("matched command prompt: %s" % self._matched_cmd_prompt)
Expand Down Expand Up @@ -1132,7 +1134,7 @@ def _sanitize(self, resp, command=None, strip_prompt=True):
def _find_error(self, response):
"""Searches the buffered response for a matching error condition"""
for stderr_regex in self._terminal_stderr_re:
if stderr_regex.search(response):
if stderr_regex.search(response[-REGEX_MAX_LENGTH:]):
self._log_messages(
"matched error regex (terminal_stderr_re) '%s' from response '%s'"
% (stderr_regex.pattern, response)
Expand All @@ -1149,7 +1151,7 @@ def _find_error(self, response):
def _find_prompt(self, response):
"""Searches the buffered response for a matching command prompt"""
for stdout_regex in self._terminal_stdout_re:
match = stdout_regex.search(response)
match = stdout_regex.search(response[-REGEX_MAX_LENGTH:])
if match:
self._matched_pattern = stdout_regex.pattern
self._matched_prompt = match.group()
Expand Down