Skip to content

Commit cd0a957

Browse files
committed
Merge pull request #213 from KeepSafe/add_response_started_property
Add prop
2 parents 2648c48 + 62bac2e commit cd0a957

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGES
22
=======
33

4+
0.13.1 (Unreleased)
5+
--------------------
6+
7+
- Add `aiohttp.web.StreamResponse.started` property #213
8+
9+
410
0.13.0 (12-29-2014)
511
-------------------
612

aiohttp/web.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ def _copy_cookies(self):
409409
value = cookie.output(header='')[1:]
410410
self.headers.add('Set-Cookie', value)
411411

412+
@property
413+
def started(self):
414+
return self._resp_impl is not None
415+
412416
@property
413417
def status(self):
414418
return self._status

docs/web.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ StreamResponse
474474
parameter. Otherwise pass :class:`str` with
475475
arbitrary *status* explanation..
476476

477+
.. attribute:: started
478+
479+
Read-only :class:`bool` property, ``True`` if :meth:`start` has
480+
been called, ``False`` otherwise.
481+
477482
.. attribute:: status
478483

479484
Read-only property for *HTTP response status code*, :class:`int`.

tests/test_web_response.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,12 @@ def test_set_text_with_charset(self):
425425
self.assertEqual("текст", resp.text)
426426
self.assertEqual("текст".encode('koi8-r'), resp.body)
427427
self.assertEqual("koi8-r", resp.charset)
428+
429+
def test_started_when_not_started(self):
430+
resp = StreamResponse()
431+
self.assertFalse(resp.started)
432+
433+
def test_started_when_started(self):
434+
resp = StreamResponse()
435+
resp.start(self.make_request('GET', '/'))
436+
self.assertTrue(resp.started)

0 commit comments

Comments
 (0)