Skip to content

Commit

Permalink
Deprecate app.make_handler() (aio-libs#2938)
Browse files Browse the repository at this point in the history
  • Loading branch information
xstrengthofonex authored and thehesiod committed Apr 26, 2018
1 parent 03cfcda commit 45dc95f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
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 @@ -132,9 +134,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

0 comments on commit 45dc95f

Please sign in to comment.