Skip to content
Myr

insanity for chunked iteration

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 29271a4 · Browse files · 1 file+31 added−5 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+31 added−5 removed

  • other:+31 added−5 removed

1 file+31 added−5 removed

modified:requests/models.py+31 added-5 removed
609 unmodified lines
610 if not chunk:611 break612 yield chunk613 self._content_consumed = True614 615 def generate_chunked():616 resp = self.raw._original_response617 fp = resp.fp618 yield fp.read(resp.chunk_left)619 while 1:620 #XXX correct line size621 pending_bytes = fp.readline(80).strip()622 if not pending_bytes:623 break624 pending_bytes = int(pending_bytes, 16)625 if pending_bytes == 0:626 break627 while pending_bytes:628 chunk = fp.read(min(chunk_size, pending_bytes))629 pending_bytes-=len(chunk)630 yield chunk631 self._content_consumed = True632615 gen = generate()633634 if getattr(self.raw._original_response, 'chunked', False):635 gen = generate_chunked()636 else:637 gen = generate()638639 if 'gzip' in self.headers.get('content-encoding', ''):640 gen = stream_decompress(gen, mode='gzip')641 elif 'deflate' in self.headers.get('content-encoding', ''):642 gen = stream_decompress(gen, mode='deflate')
20 unmodified lines
663 lines = chunk.splitlines(True)664 for line in lines[:-1]:665 yield line.rstrip()666 # Save the last part of the chunk for next iteration, to keep full line together667 # lines may be empty for the last chunk of a chunked response668 if lines:645 pending = lines[-1]646 #if pending is a complete line, give it baack647 if pending[-1] == '\n':648 yield pending.rstrip()669 pending = lines[-1]670 #if pending is a complete line, give it baack671 if pending[-1] == '\n':672 yield pending.rstrip()673 pending = None674 else:675 pending = None676677 # Yield the last line678 if pending is not None:
59 unmodified lines