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

Add prop #213

Merged
merged 2 commits into from
Dec 29, 2014
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
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGES
=======

0.13.1 (Unreleased)
--------------------

- Add `aiohttp.web.StreamResponse.started` property #213


0.13.0 (12-29-2014)
-------------------

Expand Down
4 changes: 4 additions & 0 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ def _copy_cookies(self):
value = cookie.output(header='')[1:]
self.headers.add('Set-Cookie', value)

@property
def started(self):
return self._resp_impl is not None

@property
def status(self):
return self._status
Expand Down
5 changes: 5 additions & 0 deletions docs/web.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,11 @@ StreamResponse
parameter. Otherwise pass :class:`str` with
arbitrary *status* explanation..

.. attribute:: started

Read-only :class:`bool` property, ``True`` if :meth:`start` has
been called, ``False`` otherwise.

.. attribute:: status

Read-only property for *HTTP response status code*, :class:`int`.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,12 @@ def test_set_text_with_charset(self):
self.assertEqual("текст", resp.text)
self.assertEqual("текст".encode('koi8-r'), resp.body)
self.assertEqual("koi8-r", resp.charset)

def test_started_when_not_started(self):
resp = StreamResponse()
self.assertFalse(resp.started)

def test_started_when_started(self):
resp = StreamResponse()
resp.start(self.make_request('GET', '/'))
self.assertTrue(resp.started)