From 9375b2c155e9d0a3760516408153ae16733007f0 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 29 Dec 2014 21:30:26 +0200 Subject: [PATCH 1/2] Add prop --- aiohttp/web.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aiohttp/web.py b/aiohttp/web.py index 252a3c5d85..b611419ca6 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -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 From 62bac2e698c6927d525acb32affa05bf1b615b8b Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 29 Dec 2014 21:56:50 +0200 Subject: [PATCH 2/2] Add tests, docs and CHANGES for resp.started --- CHANGES.txt | 6 ++++++ docs/web.rst | 5 +++++ tests/test_web_response.py | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 0dc82057fa..aacf66d7fc 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,12 @@ CHANGES ======= +0.13.1 (Unreleased) +-------------------- + +- Add `aiohttp.web.StreamResponse.started` property #213 + + 0.13.0 (12-29-2014) ------------------- diff --git a/docs/web.rst b/docs/web.rst index f17d453625..99a4e981d9 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -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`. diff --git a/tests/test_web_response.py b/tests/test_web_response.py index 8356a8158f..865d108630 100644 --- a/tests/test_web_response.py +++ b/tests/test_web_response.py @@ -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)