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

Deprecate app.make_handler() #2938

Merged
merged 5 commits into from
Apr 19, 2018
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
1 change: 1 addition & 0 deletions CHANGES/2938.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate Application.make_handler()
22 changes: 18 additions & 4 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -253,6 +253,20 @@ 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("Application.make_handler(...) is deprecated, "
"use AppRunner API instead",
DeprecationWarning,
stacklevel=2)

return self._make_handler(loop=loop,
access_log_class=access_log_class,
**kwargs)

async def startup(self):
"""Causes on_startup signal

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
9 changes: 5 additions & 4 deletions docs/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ 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.
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`
instance to override default logger.
Expand Down Expand Up @@ -120,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.Application.make_handler` call.
To use different logger name please pass *logger* parameter
(:class:`logging.Logger` instance) to :meth:`aiohttp.web.AppRunner` constructor.


.. _access_logformat:
Expand Down
5 changes: 3 additions & 2 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/autobahn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions tests/test_web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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):

Expand All @@ -89,13 +89,20 @@ 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,
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)
Expand Down