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 2 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()
19 changes: 15 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,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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace @make_handler with Application.make_handler(...) and add a test for making sure that deprecation warning is raised.

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()
3 changes: 2 additions & 1 deletion docs/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the deprecation but replace aiohttp.web.Application.make_handler with aiohttp.web.AppRunner / aiohttp.web.run_app()


Pass *access_log* parameter with value of :class:`logging.Logger`
instance to override default logger.
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same


.. _access_logformat:
http://docs.gunicorn.org/en/stable/settings.html#access-log-format
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
8 changes: 4 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,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,
Expand Down