Skip to content

Commit a7c85d8

Browse files
Use iter_lines instead of custom buffer logic
1 parent def6471 commit a7c85d8

1 file changed

Lines changed: 7 additions & 21 deletions

File tree

src/lara_sdk/_client.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,10 @@ def _request_stream(self, method: str, path: str, body: Dict = None, files: Dict
192192
if not (200 <= response.status_code < 300):
193193
raise LaraApiError.from_response(response)
194194

195-
buffer = ''
196-
for chunk in response.iter_content(chunk_size=None, decode_unicode=True):
197-
if chunk:
198-
buffer += chunk
199-
lines = buffer.split('\n')
200-
buffer = lines.pop()
201-
202-
for line in lines:
203-
if line.strip():
204-
try:
205-
parsed = json.loads(line)
206-
yield parsed.get('data', parsed).get('content')
207-
except (json.JSONDecodeError, AttributeError):
208-
pass
209-
210-
if buffer.strip():
211-
try:
212-
parsed = json.loads(buffer)
213-
yield parsed.get('data', parsed).get('content')
214-
except (json.JSONDecodeError, AttributeError):
215-
pass
195+
for line in response.iter_lines(decode_unicode=True):
196+
if line:
197+
try:
198+
parsed = json.loads(line)
199+
yield parsed.get('data', parsed).get('content')
200+
except (json.JSONDecodeError, AttributeError):
201+
pass

0 commit comments

Comments
 (0)