Skip to content
Myr

make Response.iter_lines yield the pending buffer if its actually a complete line

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ronny Pfannschmidt · committed by Ronny Pfannschmidt · parent df0dc2b · Browse files · 1 file+5 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−1 removed

  • other:+5 added−1 removed

1 file+5 added−1 removed

modified:requests/models.py+5 added-1 removed
631 unmodified lines
632 """Iterates over the response data, one line at a time. This633 avoids reading the content at once into memory for large634 responses.635 """636636 #XXX: why rstrip by default637 pending = None638 for chunk in self.iter_content(chunk_size, decode_unicode=decode_unicode):639 if pending is not None:640 chunk = pending + chunk
1 unmodified line
642 for line in lines[:-1]:643 yield line.rstrip()644 # Save the last part of the chunk for next iteration, to keep full line together645 pending = lines[-1]646 #if pending is a complete line, give it baack647 if pending[-1] == '\n':648 yield pending.rstrip()649 pending = None650651 # Yield the last line652 if pending is not None:653 yield pending.rstrip()
58 unmodified lines