Changes for issue 2358

Changes made in wacth.py to print Empty newlines that are skipped when watching pod logs.
This commit is contained in:
Raj Bhargav 2025-03-08 20:45:32 +05:30 committed by GitHub
parent d80165da21
commit d1adc8a544
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -71,6 +71,7 @@ def iter_resp_lines(resp):
# Split by newline (safe for utf-8 because multi-byte sequences cannot contain the newline byte)
next_newline = buffer.find(b'\n')
last_was_empty = False # Set empty-line flag
while next_newline != -1:
# Convert bytes to a valid utf-8 string, replacing any invalid utf-8 with the '<27>' character
line = buffer[:next_newline].decode(
@ -78,6 +79,11 @@ def iter_resp_lines(resp):
buffer = buffer[next_newline+1:]
if line:
yield line
last_was_empty = False # Reset empty-line flag
else:
if not last_was_empty:
yield '\n' # Only print one empty line
last_was_empty = True # Mark that we handled an empty line
next_newline = buffer.find(b'\n')
@ -175,6 +181,7 @@ class Watch(object):
while True:
resp = func(*args, **kwargs)
try:
last_was_empty = False # Set empty line false
for line in iter_resp_lines(resp):
# unmarshal when we are receiving events from watch,
# return raw string when we are streaming log
@ -198,7 +205,12 @@ class Watch(object):
retry_after_410 = False
yield event
else:
yield line
if line:
yield line # Normal non-empty line
last_was_empty = False
elif not last_was_empty:
yield '/n' # Only yield one empty line
last_was_empty = True
if self._stop:
break
finally: