Skip to content
Myr

even more evil, fixes my misstakes with chunked reading

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 5cfbb0a · Browse files · 2 files+14 added−7 removed
This commit

State

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

Diff stats

2 files+14 added−7 removed

  • other:+14 added−7 removed

2 files+14 added−7 removed

modified:requests/models.py+12 added-5 removed
613 unmodified lines
614 615 def generate_chunked():616 resp = self.raw._original_response617 fp = resp.fp618 if resp.chunk_left:618 yield fp.read(resp.chunk_left)619 yield fp.read(resp.chunk_left)620 fp.read(2) #throw away crlf621 while 1:622 #XXX correct line size621 pending_bytes = fp.readline(80).strip()622 if not pending_bytes:623 break623 pending_bytes = fp.readline(40).strip()624 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 fp.read(2) # throw away crlf632 self._content_consumed = True633634634 if getattr(self.raw._original_response, 'chunked', False):635 if getattr(getattr(self.raw, '_original_response', None), 'chunked', False):636 gen = generate_chunked()637638 def hack_gen(gen=gen):639 for item in gen:640 print repr(item)641 yield item642 gen = hack_gen()643 else:644 gen = generate()645646 if 'gzip' in self.headers.get('content-encoding', ''):
98 unmodified lines
modified:test_requests.py+2 added-2 removed
606 unmodified lines
607608 lines = (0, 2, 10, 100)609610 for i in lines:611611 r = requests.get(httpbin('stream', str(i)), prefetch=False)613 len_lines = len([l for l in r.iter_lines()])612 lines = list(r.iter_lines())613 len_lines = len(lines)614615 self.assertEqual(i, len_lines)616617 # Test 'dangling' fragment in responses that do not terminate in
41 unmodified lines