@@ -71,13 +71,19 @@ def iter_resp_lines(resp):
71
71
72
72
# Split by newline (safe for utf-8 because multi-byte sequences cannot contain the newline byte)
73
73
next_newline = buffer .find (b'\n ' )
74
+ last_was_empty = False # Set empty-line flag
74
75
while next_newline != - 1 :
75
76
# Convert bytes to a valid utf-8 string, replacing any invalid utf-8 with the '�' character
76
77
line = buffer [:next_newline ].decode (
77
78
"utf-8" , errors = "replace" )
78
79
buffer = buffer [next_newline + 1 :]
79
80
if line :
80
81
yield line
82
+ last_was_empty = False # Reset empty-line flag
83
+ else :
84
+ if not last_was_empty :
85
+ yield '\n ' # Only print one empty line
86
+ last_was_empty = True # Mark that we handled an empty line
81
87
next_newline = buffer .find (b'\n ' )
82
88
83
89
@@ -175,6 +181,7 @@ def stream(self, func, *args, **kwargs):
175
181
while True :
176
182
resp = func (* args , ** kwargs )
177
183
try :
184
+ last_was_empty = False # Set empty line false
178
185
for line in iter_resp_lines (resp ):
179
186
# unmarshal when we are receiving events from watch,
180
187
# return raw string when we are streaming log
@@ -198,7 +205,12 @@ def stream(self, func, *args, **kwargs):
198
205
retry_after_410 = False
199
206
yield event
200
207
else :
201
- yield line
208
+ if line :
209
+ yield line # Normal non-empty line
210
+ last_was_empty = False
211
+ elif not last_was_empty :
212
+ yield '/n' # Only yield one empty line
213
+ last_was_empty = True
202
214
if self ._stop :
203
215
break
204
216
finally :
0 commit comments