Skip to content
Myr

Adding a custom line delimiter to iter_lines()

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

authored by Val Tenyotkin · committed by Val Tenyotkin · parent 6b58a35 · Browse files · 1 file+6 added−2 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+6 added−2 removed

  • other:+6 added−2 removed

1 file+6 added−2 removed

modified:requests/models.py+6 added-2 removed
680 unmodified lines
681 chunks = stream_decode_response_unicode(chunks, self)682683 return chunks684685 def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None):685 def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None, newline=None):686 """Iterates over the response data, one line at a time. When687 stream=True is set on the request, this avoids reading the688 content at once into memory for large responses.689 """
3 unmodified lines
693 for chunk in self.iter_content(chunk_size=chunk_size, decode_unicode=decode_unicode):694695 if pending is not None:696 chunk = pending + chunk697 lines = chunk.splitlines()697698 if newline:699 lines = chunk.split(newline)700 else:701 lines = chunk.splitlines()702703 if lines and lines[-1] and chunk and lines[-1][-1] == chunk[-1]:704 pending = lines.pop()705 else:706 pending = None
131 unmodified lines