From eac9ccfa3f824a4236fc393c70ff4a043adbd1c0 Mon Sep 17 00:00:00 2001 From: Pavel Kamaev Date: Wed, 31 May 2017 12:46:08 +0300 Subject: [PATCH 1/8] fixed consecutive calling for write_eof on Response --- aiohttp/web_response.py | 2 ++ tests/test_web_response.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/aiohttp/web_response.py b/aiohttp/web_response.py index f096c86556a..65179635e57 100644 --- a/aiohttp/web_response.py +++ b/aiohttp/web_response.py @@ -563,6 +563,8 @@ def content_length(self, value): @asyncio.coroutine def write_eof(self): + if self._eof_sent: + return body = self._body if body is not None: if (self._req._method == hdrs.METH_HEAD or diff --git a/tests/test_web_response.py b/tests/test_web_response.py index 6a407cbdcd1..12ffdbd4fcc 100644 --- a/tests/test_web_response.py +++ b/tests/test_web_response.py @@ -889,6 +889,20 @@ def test_send_set_cookie_header(buf, writer): 'Server: .+\r\n\r\n', txt) +@asyncio.coroutine +def test_consecutive_write_eof(): + req = make_request('GET', '/') + data = b'data' + resp = Response(body=data) + + yield from resp.prepare(req) + with mock.patch('aiohttp.web.StreamResponse.write_eof') as super_write_eof: + yield from resp.write_eof() + resp._eof_sent = True + yield from resp.write_eof() + super_write_eof.assert_called_once_with(data) + + def test_set_text_with_content_type(): resp = Response() resp.content_type = "text/html" From d166ad4812de85bb0624a941cef446d2ad7521ee Mon Sep 17 00:00:00 2001 From: Pavel Kamaev Date: Fri, 2 Jun 2017 10:48:19 +0300 Subject: [PATCH 2/8] fixed consecutive calling for write_eof on Response added records to CHANGES.rst and CONTRIBUTORS.txt --- CHANGES.rst | 2 +- CONTRIBUTORS.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1821498286e..03786c649df 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changes 2.2.0 (2017-xx-xx) ------------------ -- +- Fixed consecutive calls for `Response.write_eof`. - diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index b4daae584f1..36c60e39263 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -128,6 +128,7 @@ Pankaj Pandey Pau Freixes Paul Colomiets Paulus Schoutsen +Pavel Kamaev Pawel Miech Philipp A. Rafael Viotti From 3c74bc5f4a717c66a66bb832a6b30933e42d849a Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Wed, 31 May 2017 05:07:59 -0700 Subject: [PATCH 3/8] Update pytest from 3.1.0 to 3.1.1 --- requirements-ci.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-ci.txt b/requirements-ci.txt index 7eca0775b1f..b5e61650c34 100644 --- a/requirements-ci.txt +++ b/requirements-ci.txt @@ -12,7 +12,7 @@ multidict==2.1.6 async-timeout==1.2.1 sphinxcontrib-asyncio==0.2.0 sphinxcontrib-newsfeed==0.1.4 -pytest==3.1.0 +pytest==3.1.1 pytest-cov==2.5.1 pytest-mock==1.6.0 pytest-timeout==1.2.0 From 99f4d0d70fe5563cb67d597f689f5a818e0e008c Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Wed, 31 May 2017 05:08:00 -0700 Subject: [PATCH 4/8] Update pytest from 3.1.0 to 3.1.1 --- requirements-wheel.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-wheel.txt b/requirements-wheel.txt index 74048963971..79387d65b9e 100644 --- a/requirements-wheel.txt +++ b/requirements-wheel.txt @@ -1,3 +1,3 @@ cython==0.25.2 -pytest==3.1.0 +pytest==3.1.1 twine==1.9.1 From 534b462b84813b30b56065209cc04db05cb21ace Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Wed, 31 May 2017 15:47:56 -0700 Subject: [PATCH 5/8] Update ipython from 6.0.0 to 6.1.0 --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 771ad561473..491b0e68c40 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ -r requirements-ci.txt ipdb==0.10.3 pytest-sugar==0.8.0 -ipython==6.0.0 +ipython==6.1.0 aiodns==1.1.1 From 9f631417fb7ddcc9f5019c59b1f23a4caa0ed094 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 1 Jun 2017 22:51:02 +0300 Subject: [PATCH 6/8] Add doc for add_head, update doc for add_get. (#1944) * Add doc for add_head, update doc for add_get. * Update CHANGES --- CHANGES.rst | 2 ++ aiohttp/web_urldispatcher.py | 28 +++++++++++++++------------- docs/web_reference.rst | 29 ++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 03786c649df..6af42d2ffeb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Changes 2.2.0 (2017-xx-xx) ------------------ +- Add doc for add_head, update doc for add_get. #1944 + - Fixed consecutive calls for `Response.write_eof`. - diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index 4e10ce410ee..04c4b117956 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -845,13 +845,13 @@ def add_static(self, prefix, path, *, name=None, expect_handler=None, self.register_resource(resource) return resource - def add_head(self, *args, **kwargs): + def add_head(self, path, handler, **kwargs): """ Shortcut for add_route with method HEAD """ - return self.add_route(hdrs.METH_HEAD, *args, **kwargs) + return self.add_route(hdrs.METH_HEAD, path, handler, **kwargs) - def add_get(self, *args, name=None, allow_head=True, **kwargs): + def add_get(self, path, handler, *, name=None, allow_head=True, **kwargs): """ Shortcut for add_route with method GET, if allow_head is true another route is added allowing head requests to the same endpoint @@ -860,32 +860,34 @@ def add_get(self, *args, name=None, allow_head=True, **kwargs): # it name is not None append -head to avoid it conflicting with # the GET route below head_name = name and '{}-head'.format(name) - self.add_route(hdrs.METH_HEAD, *args, name=head_name, **kwargs) - return self.add_route(hdrs.METH_GET, *args, name=name, **kwargs) + self.add_route(hdrs.METH_HEAD, path, handler, + name=head_name, **kwargs) + return self.add_route(hdrs.METH_GET, path, handler, name=name, + **kwargs) - def add_post(self, *args, **kwargs): + def add_post(self, path, handler, **kwargs): """ Shortcut for add_route with method POST """ - return self.add_route(hdrs.METH_POST, *args, **kwargs) + return self.add_route(hdrs.METH_POST, path, handler, **kwargs) - def add_put(self, *args, **kwargs): + def add_put(self, path, handler, **kwargs): """ Shortcut for add_route with method PUT """ - return self.add_route(hdrs.METH_PUT, *args, **kwargs) + return self.add_route(hdrs.METH_PUT, path, handler, **kwargs) - def add_patch(self, *args, **kwargs): + def add_patch(self, path, handler, **kwargs): """ Shortcut for add_route with method PATCH """ - return self.add_route(hdrs.METH_PATCH, *args, **kwargs) + return self.add_route(hdrs.METH_PATCH, path, handler, **kwargs) - def add_delete(self, *args, **kwargs): + def add_delete(self, path, handler, **kwargs): """ Shortcut for add_route with method DELETE """ - return self.add_route(hdrs.METH_DELETE, *args, **kwargs) + return self.add_route(hdrs.METH_DELETE, path, handler, **kwargs) def freeze(self): super().freeze() diff --git a/docs/web_reference.rst b/docs/web_reference.rst index 90518e07c8d..bc817388f2b 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -1475,14 +1475,26 @@ Router is any object that implements :class:`AbstractRouter` interface. :returns: new :class:`PlainRoute` or :class:`DynamicRoute` instance. - .. method:: add_get(path, *args, **kwargs) + .. method:: add_get(path, handler, *, name=None, allow_head=True, **kwargs) Shortcut for adding a GET handler. Calls the :meth:`add_route` with \ ``method`` equals to ``'GET'``. + If *allow_head* is ``True`` (default) the route for method HEAD + is added with the same handler as for GET. + + If *name* is provided the name for HEAD route is suffixed with + ``'-head'``. For example ``router.add_get(path, handler, + name='route')`` call adds two routes: first for GET with name + ``'route'`` and second for HEAD with name ``'route-head'``. + .. versionadded:: 1.0 - .. method:: add_post(path, *args, **kwargs) + .. versionchanged:: 2.0 + + *allow_head* parameter added. + + .. method:: add_post(path, handler, **kwargs) Shortcut for adding a POST handler. Calls the :meth:`add_route` with \ @@ -1491,21 +1503,28 @@ Router is any object that implements :class:`AbstractRouter` interface. .. versionadded:: 1.0 - .. method:: add_put(path, *args, **kwargs) + .. method:: add_head(path, handler, **kwargs) + + Shortcut for adding a HEAD handler. Calls the :meth:`add_route` with \ + ``method`` equals to ``'HEAD'``. + + .. versionadded:: 1.0 + + .. method:: add_put(path, handler, **kwargs) Shortcut for adding a PUT handler. Calls the :meth:`add_route` with \ ``method`` equals to ``'PUT'``. .. versionadded:: 1.0 - .. method:: add_patch(path, *args, **kwargs) + .. method:: add_patch(path, handler, **kwargs) Shortcut for adding a PATCH handler. Calls the :meth:`add_route` with \ ``method`` equals to ``'PATCH'``. .. versionadded:: 1.0 - .. method:: add_delete(path, *args, **kwargs) + .. method:: add_delete(path, handler, **kwargs) Shortcut for adding a DELETE handler. Calls the :meth:`add_route` with \ ``method`` equals to ``'DELETE'``. From 78fbe340b87504b7a767dd945f0d4f089952a554 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 1 Jun 2017 22:58:07 +0300 Subject: [PATCH 7/8] Fix deprecation warning in test suite --- tests/test_connector.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_connector.py b/tests/test_connector.py index ccdaab0243c..ccee517743e 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -638,7 +638,9 @@ def test_tcp_connector_ctor(loop): def test_tcp_connector_ctor_fingerprint_valid(loop): valid = b'\xa2\x06G\xad\xaa\xf5\xd8\\J\x99^by;\x06=' - conn = aiohttp.TCPConnector(loop=loop, fingerprint=valid) + # md5 and sha1 are deprecated + with pytest.warns(DeprecationWarning): + conn = aiohttp.TCPConnector(loop=loop, fingerprint=valid) assert conn.fingerprint == valid From 01c1e5dffcdb8ae06b0a25f92a3f9ca1cda8824b Mon Sep 17 00:00:00 2001 From: Pavel Kamaev Date: Fri, 2 Jun 2017 10:53:26 +0300 Subject: [PATCH 8/8] fixed consecutive calling for write_eof on Response fixed merge conflicts --- CHANGES.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 6af42d2ffeb..128bb37f17c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -24,8 +24,6 @@ Changes - -- - 2.1.0 (2017-05-26) ------------------