From 4077c14266f79c976ea14dd40b5af9fe5349c596 Mon Sep 17 00:00:00 2001 From: Vincent White Date: Sun, 15 Apr 2018 02:03:00 +0900 Subject: [PATCH 1/5] Deprecate app.make_handler() --- CHANGES/2936.removal | 1 + aiohttp/web_app.py | 19 +++++++++++++++---- aiohttp/web_runner.py | 2 +- docs/logging.rst | 3 ++- docs/testing.rst | 5 +++-- tests/autobahn/server.py | 2 +- tests/test_web_app.py | 8 ++++---- 7 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 CHANGES/2936.removal diff --git a/CHANGES/2936.removal b/CHANGES/2936.removal new file mode 100644 index 00000000000..1f6bca516e7 --- /dev/null +++ b/CHANGES/2936.removal @@ -0,0 +1 @@ +Deprecate Application.make_handler() diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index 5bd01639e47..ce70184710a 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -230,10 +230,10 @@ def router(self): def middlewares(self): return self._middlewares - def make_handler(self, *, - loop=None, - access_log_class=AccessLogger, - **kwargs): + def _make_handler(self, *, + loop=None, + access_log_class=AccessLogger, + **kwargs): if not issubclass(access_log_class, AbstractAccessLogger): raise TypeError( @@ -253,6 +253,17 @@ def make_handler(self, *, access_log_class=access_log_class, loop=self.loop, **kwargs) + def make_handler(self, *, + loop=None, + access_log_class=AccessLogger, + **kwargs): + warnings.warn("@make_handler is deprecated", + DeprecationWarning, + stacklevel=2) + return self._make_handler(loop=loop, + access_log_class=access_log_class, + **kwargs) + async def startup(self): """Causes on_startup signal diff --git a/aiohttp/web_runner.py b/aiohttp/web_runner.py index fcff47cddee..934b98cf7ac 100644 --- a/aiohttp/web_runner.py +++ b/aiohttp/web_runner.py @@ -269,7 +269,7 @@ async def _make_server(self): await self._app.startup() self._app.freeze() - return self._app.make_handler(loop=loop, **self._kwargs) + return self._app._make_handler(loop=loop, **self._kwargs) async def _cleanup_server(self): await self._app.cleanup() diff --git a/docs/logging.rst b/docs/logging.rst index f407bb3bf2a..f3b8461737f 100644 --- a/docs/logging.rst +++ b/docs/logging.rst @@ -32,6 +32,7 @@ Access log by default is switched on and uses ``'aiohttp.access'`` logger name. The log may be controlled by :meth:`aiohttp.web.Application.make_handler` call. +.. deprecated:: 3.2 Pass *access_log* parameter with value of :class:`logging.Logger` instance to override default logger. @@ -123,7 +124,7 @@ The log is enabled by default. To use different logger name please specify *logger* parameter (:class:`logging.Logger` instance) on performing :meth:`aiohttp.web.Application.make_handler` call. - +.. deprecated:: 3.2 .. _access_logformat: http://docs.gunicorn.org/en/stable/settings.html#access-log-format diff --git a/docs/testing.rst b/docs/testing.rst index 0455e2ef3c6..e790f479d82 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -153,6 +153,7 @@ Pytest tooling has the following fixtures: :meth:`aiohttp.web.Application.make_handler` .. versionchanged:: 3.0 + .. deprecated:: 3.2 The fixture was renamed from ``test_server`` to ``aiohttp_server``. @@ -685,8 +686,8 @@ Test Client .. attribute:: app - An alias for :attr:`self.server.app`. return ``None`` if - ``self.server`` is not :class:`TestServer` + An alias for :attr:`self.server.app`. return ``None`` if + ``self.server`` is not :class:`TestServer` instance(e.g. :class:`RawTestServer` instance for test low-level server). .. attribute:: session diff --git a/tests/autobahn/server.py b/tests/autobahn/server.py index eed75dd452c..0a1a0e36505 100644 --- a/tests/autobahn/server.py +++ b/tests/autobahn/server.py @@ -34,7 +34,7 @@ async def main(loop): app = web.Application() app.router.add_route('GET', '/', wshandler) - handler = app.make_handler() + handler = app._make_handler() srv = await loop.create_server(handler, '127.0.0.1', 9001) print("Server started at http://127.0.0.1:9001") return app, srv, handler diff --git a/tests/test_web_app.py b/tests/test_web_app.py index 5fbbcb81bdd..adc7c1a09c3 100644 --- a/tests/test_web_app.py +++ b/tests/test_web_app.py @@ -54,7 +54,7 @@ def test_app_make_handler_debug_exc(loop, mocker, debug): app = web.Application(debug=debug) srv = mocker.patch('aiohttp.web_app.Server') - app.make_handler(loop=loop) + app._make_handler(loop=loop) srv.assert_called_with(app._handle, request_factory=app._make_request, access_log_class=mock.ANY, @@ -66,7 +66,7 @@ def test_app_make_handler_args(loop, mocker): app = web.Application(handler_args={'test': True}) srv = mocker.patch('aiohttp.web_app.Server') - app.make_handler(loop=loop) + app._make_handler(loop=loop) srv.assert_called_with(app._handle, request_factory=app._make_request, access_log_class=mock.ANY, @@ -80,7 +80,7 @@ class Logger: app = web.Application() with pytest.raises(TypeError): - app.make_handler(access_log_class=Logger, loop=loop) + app._make_handler(access_log_class=Logger, loop=loop) class Logger(AbstractAccessLogger): @@ -89,7 +89,7 @@ def log(self, request, response, time): srv = mocker.patch('aiohttp.web_app.Server') - app.make_handler(access_log_class=Logger, loop=loop) + app._make_handler(access_log_class=Logger, loop=loop) srv.assert_called_with(app._handle, access_log_class=Logger, request_factory=app._make_request, From fd23cb56764d9ec8b72254fddae00398dc20b623 Mon Sep 17 00:00:00 2001 From: Vincent White Date: Sun, 15 Apr 2018 02:10:33 +0900 Subject: [PATCH 2/5] edit CHANGES filename to correct issue number --- CHANGES/{2936.removal => 2938.removal} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CHANGES/{2936.removal => 2938.removal} (100%) diff --git a/CHANGES/2936.removal b/CHANGES/2938.removal similarity index 100% rename from CHANGES/2936.removal rename to CHANGES/2938.removal From 0372ba273ed315034923252ef904b9c7de999274 Mon Sep 17 00:00:00 2001 From: Vincent White Date: Thu, 19 Apr 2018 01:08:31 +0900 Subject: [PATCH 3/5] Add test for make_handler deprecation and update logging.rst --- aiohttp/web_app.py | 4 +++- docs/logging.rst | 8 ++++---- tests/test_web_app.py | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index ce70184710a..253f7a9a573 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -257,9 +257,11 @@ def make_handler(self, *, loop=None, access_log_class=AccessLogger, **kwargs): - warnings.warn("@make_handler is deprecated", + + warnings.warn("Application.make_handler(...) is deprecated", DeprecationWarning, stacklevel=2) + return self._make_handler(loop=loop, access_log_class=access_log_class, **kwargs) diff --git a/docs/logging.rst b/docs/logging.rst index f3b8461737f..bded120bbe3 100644 --- a/docs/logging.rst +++ b/docs/logging.rst @@ -31,8 +31,8 @@ Access logs Access log by default is switched on and uses ``'aiohttp.access'`` logger name. -The log may be controlled by :meth:`aiohttp.web.Application.make_handler` call. -.. deprecated:: 3.2 +The log may be controlled by :meth:`aiohttp.web.AppRunner / aiohttp.web.run_app()` call. + Pass *access_log* parameter with value of :class:`logging.Logger` instance to override default logger. @@ -123,8 +123,8 @@ The log is enabled by default. To use different logger name please specify *logger* parameter (:class:`logging.Logger` instance) on performing -:meth:`aiohttp.web.Application.make_handler` call. -.. deprecated:: 3.2 +:meth:`aiohttp.web.AppRunner / aiohttp.web.run_app()` call. + .. _access_logformat: http://docs.gunicorn.org/en/stable/settings.html#access-log-format diff --git a/tests/test_web_app.py b/tests/test_web_app.py index adc7c1a09c3..770e75d8ca5 100644 --- a/tests/test_web_app.py +++ b/tests/test_web_app.py @@ -96,6 +96,13 @@ def log(self, request, response, time): loop=loop, debug=mock.ANY) +def test_app_make_handler_raises_deprecation_warning(loop): + app = web.Application() + + with pytest.warns(DeprecationWarning): + app.make_handler(loop=loop) + + async def test_app_register_on_finish(): app = web.Application() cb1 = make_mocked_coro(None) From ab2261560e2d1a2f269ce46d83d46cd27e14f4a1 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 18 Apr 2018 21:51:30 +0300 Subject: [PATCH 4/5] Update web_app.py --- aiohttp/web_app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index 253f7a9a573..bebad310bdc 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -258,7 +258,8 @@ def make_handler(self, *, access_log_class=AccessLogger, **kwargs): - warnings.warn("Application.make_handler(...) is deprecated", + warnings.warn("Application.make_handler(...) is deprecated, " + "use AppRunner API instead", DeprecationWarning, stacklevel=2) From 281a0b930f773ed85235de29630d05e16c944bd8 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 18 Apr 2018 21:55:41 +0300 Subject: [PATCH 5/5] Update logging.rst --- docs/logging.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/logging.rst b/docs/logging.rst index bded120bbe3..fc8a2ccd14d 100644 --- a/docs/logging.rst +++ b/docs/logging.rst @@ -31,7 +31,8 @@ Access logs Access log by default is switched on and uses ``'aiohttp.access'`` logger name. -The log may be controlled by :meth:`aiohttp.web.AppRunner / aiohttp.web.run_app()` call. +The log may be controlled by :meth:`aiohttp.web.AppRunner` and +:func:`aiohttp.web.run_app`. Pass *access_log* parameter with value of :class:`logging.Logger` @@ -121,9 +122,8 @@ given on web requests handling. The log is enabled by default. -To use different logger name please specify *logger* parameter -(:class:`logging.Logger` instance) on performing -:meth:`aiohttp.web.AppRunner / aiohttp.web.run_app()` call. +To use different logger name please pass *logger* parameter +(:class:`logging.Logger` instance) to :meth:`aiohttp.web.AppRunner` constructor. .. _access_logformat: