Skip to content
Myr

iter_lines!

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 5a3aae7 · Browse files · 1 file+46 added−0 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+46 added−0 removed

  • other:+46 added−0 removed

1 file+46 added−0 removed

modified:requests/models.py+46 added
570 unmodified lines
571572 return gen573574575 def iter_lines(self, newlines=None, decode_unicode=None):576 """Iterates over the response data, one line at a time. This577 avoids reading the content at once into memory for large578 responses.579580 :param newlines: a collection of bytes to seperate lines with.581 """582583 if newlines is None:584 newlines = ('\r', '\n', '\r\n')585586 if self._content_consumed:587 raise RuntimeError(588 'The content for this response was already consumed'589 )590591 def generate():592 chunk = []593594 while 1:595 c = self.raw.read(1)596 if not c:597 break598599 if c in newlines:600 yield ''.join(chunk)601 chunk = []602 else:603 chunk.append(c)604605 self._content_consumed = True606607 gen = generate()608609 if 'gzip' in self.headers.get('content-encoding', ''):610 gen = stream_decode_gzip(gen)611612 if decode_unicode is None:613 decode_unicode = self.config.get('decode_unicode')614615 if decode_unicode:616 gen = stream_decode_response_unicode(gen, self)617618 return gen619620621 @property622 def content(self):623 """Content of the response, in bytes or unicode624 (if available).
59 unmodified lines