Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

#69 Fixing 0.3.0 expect match issue when channel receives multiple lines … #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions paramiko_expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def expect(
if re.match(default_match_prefix + re_string + '$',
current_buffer_output_decoded, re.DOTALL)]
):
current_buffer_output_decoded = ''
# avoids paramiko hang when recv is not ready yet
while not self.channel.recv_ready():
time.sleep(.009)
Expand Down Expand Up @@ -188,7 +187,7 @@ def expect(

# Add the currently read buffer to the output
self.current_output += current_buffer_decoded
current_buffer_output_decoded = '\n' + self.current_output.splitlines()[-1]
current_buffer_output_decoded = '\n' + current_buffer_decoded

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the latest output for any matches instead of all the total output - Requires current_output_line = 0 to be initialized before the while loop

Suggested change
current_buffer_output_decoded = '\n' + current_buffer_decoded
# Add the currently read buffer to the output
self.current_output += current_buffer_decoded
output_lines = self.current_output.splitlines()
# Check the latest output for any matches
current_buffer_output_decoded = '\n' + '\n'.join(output_lines[current_output_line:])
# Update current line in output that has been checked
current_output_line += len(output_lines[current_output_line:]) - 1


# Grab the first pattern that was matched
if len(re_strings) != 0:
Expand Down