Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix response.text property #420

Merged
merged 1 commit into from
Jun 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ def body(self, body):

@property
def text(self):
if self._body is None:
return None
return self._body.decode(self.charset or 'utf-8')

@text.setter
Expand Down
5 changes: 5 additions & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,8 @@ def test_text_in_ctor_with_content_type_header(self):
self.assertEqual('текст'.encode('koi8-r'), resp.body)
self.assertEqual('text/html', resp.content_type)
self.assertEqual('koi8-r', resp.charset)

def test_text_with_empty_payload(self):
resp = Response(status=200)
self.assertEqual(resp.body, None)
self.assertEqual(resp.text, None)