Make Response.content return None if raw is None

Add test.
This commit is contained in:
Nicola Soranzo
2016-11-24 12:53:49 +00:00
parent 4f428228d7
commit f897be58bf
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -769,7 +769,7 @@ class Response(object):
raise RuntimeError(
'The content for this response was already consumed')
if not self.status_code:
if self.status_code == 0 or self.raw is None:
self._content = None
else:
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
+4
View File
@@ -1094,6 +1094,10 @@ class TestRequests:
total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
assert total_seconds > 0.0
def test_empty_response_has_content_none(self):
r = requests.Response()
assert r.content is None
def test_response_is_iterable(self):
r = requests.Response()
io = StringIO.StringIO('abc')