Skip to content
Myr

Merge pull request #3718 from nsoranzo/master

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

Make Response.content() return None for an empty response

authored by Cory Benfield · committed by GitHub · parents dfad00a, f897be5 · Browse files · 2 files+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

2 files+5 added−1 removed

  • tests:+4 added−0 removed
  • other:+1 added−1 removed

2 files+5 added−1 removed

modified:requests/models.py+1 added-1 removed
767 unmodified lines
768 if self._content_consumed:769 raise RuntimeError(770 'The content for this response was already consumed')771772 if self.status_code == 0:772 if self.status_code == 0 or self.raw is None:773 self._content = None774 else:775 self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()776
124 unmodified lines
modified:tests/test_requests.py+4 added
1092 unmodified lines
1093 td = r.elapsed1094 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)1095 assert total_seconds > 0.010961097 def test_empty_response_has_content_none(self):1098 r = requests.Response()1099 assert r.content is None11001101 def test_response_is_iterable(self):1102 r = requests.Response()1103 io = StringIO.StringIO('abc')1104 read_ = io.read
1076 unmodified lines