Skip to content

Commit

Permalink
main: filter_output loses line prefixes
Browse files Browse the repository at this point in the history
If the watched process ends a push to the pipe without a newline at the
end, but with newlines in the middle, then sep_rx.split() will return
with multiple entries, the last of which will not end with a newline
and yet not be the empty string.  This line prefix needs to be stashed
into the pending buffer, too.

This turns out to be exactly the same logic as if sep_rx.split had not
split the string, so eliminate one layer of conditionals.

This version incorporates feedback from Rob Browning to continue to pass
a list to extend().

Signed-off-by: Nathaniel Filardo <[email protected]>
  • Loading branch information
nwf committed Jun 24, 2019
1 parent d8bc5a5 commit 2a277ee
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,15 @@ def filter_output(src_out, src_err, dest_out, dest_err):
print_clean_line(dest, pending.pop(fd, []), width)
else:
split = sep_rx.split(buf)
if len(split) > 2:
while len(split) > 1:
content, sep = split[:2]
split = split[2:]
print_clean_line(dest,
pending.pop(fd, []) + [content],
width,
sep)
else:
assert(len(split) == 1)
while len(split) > 1:
content, sep = split[:2]
split = split[2:]
print_clean_line(dest,
pending.pop(fd, []) + [content],
width,
sep)
assert(len(split) == 1)
if split[0] :
pending.setdefault(fd, []).extend(split)
except BaseException as ex:
pending_ex = chain_ex(add_ex_tb(ex), pending_ex)
Expand Down

0 comments on commit 2a277ee

Please sign in to comment.