From: Ben Darnell Date: Sat, 5 May 2018 18:10:33 +0000 (-0400) Subject: wsgi: Deprecate WSGIAdapter and WSGIApplication X-Git-Tag: v5.1.0b1~20^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c574dbd73a2e444b55e7e102d96804b961f86110;p=thirdparty%2Ftornado.git wsgi: Deprecate WSGIAdapter and WSGIApplication It's already kind of broken on Python 3 for multithreaded WSGI containers, and it's going to be more difficult to maintain as we move to native coroutines. Updates #2371 --- diff --git a/tornado/test/wsgi_test.py b/tornado/test/wsgi_test.py index e6ccc82ae..d32140f8b 100644 --- a/tornado/test/wsgi_test.py +++ b/tornado/test/wsgi_test.py @@ -3,6 +3,7 @@ from wsgiref.validate import validator from tornado.escape import json_decode from tornado.test.httpserver_test import TypeCheckHandler +from tornado.test.util import ignore_deprecation from tornado.testing import AsyncHTTPTestCase from tornado.web import RequestHandler, Application from tornado.wsgi import WSGIApplication, WSGIContainer, WSGIAdapter @@ -26,7 +27,7 @@ class WSGIContainerTest(AsyncHTTPTestCase): self.assertEqual(response.body, b"Hello world!") -class WSGIApplicationTest(AsyncHTTPTestCase): +class WSGIAdapterTest(AsyncHTTPTestCase): def get_app(self): class HelloHandler(RequestHandler): def get(self): @@ -40,11 +41,13 @@ class WSGIApplicationTest(AsyncHTTPTestCase): # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest - return WSGIContainer(validator(WSGIApplication([ - ("/", HelloHandler), - ("/path/(.*)", PathQuotingHandler), - ("/typecheck", TypeCheckHandler), - ]))) + with ignore_deprecation(): + return WSGIContainer(validator(WSGIAdapter( + Application([ + ("/", HelloHandler), + ("/path/(.*)", PathQuotingHandler), + ("/typecheck", TypeCheckHandler), + ])))) def test_simple(self): response = self.fetch("/") @@ -70,18 +73,29 @@ class WSGIApplicationTest(AsyncHTTPTestCase): # survives repeated disassembly and reassembly. class WSGIConnectionTest(httpserver_test.HTTPConnectionTest): def get_app(self): - return WSGIContainer(validator(WSGIApplication(self.get_handlers()))) + with ignore_deprecation(): + return WSGIContainer(validator(WSGIAdapter(Application(self.get_handlers())))) def wrap_web_tests_application(): result = {} for cls in web_test.wsgi_safe_tests: - class WSGIApplicationWrappedTest(cls): # type: ignore - def get_app(self): - self.app = WSGIApplication(self.get_handlers(), - **self.get_app_kwargs()) - return WSGIContainer(validator(self.app)) - result["WSGIApplication_" + cls.__name__] = WSGIApplicationWrappedTest + def class_factory(): + class WSGIApplicationWrappedTest(cls): # type: ignore + def setUp(self): + self.warning_catcher = ignore_deprecation() + self.warning_catcher.__enter__() + super(WSGIApplicationWrappedTest, self).setUp() + + def tearDown(self): + super(WSGIApplicationWrappedTest, self).tearDown() + self.warning_catcher.__exit__(None, None, None) + + def get_app(self): + self.app = WSGIApplication(self.get_handlers(), + **self.get_app_kwargs()) + return WSGIContainer(validator(self.app)) + result["WSGIApplication_" + cls.__name__] = class_factory() return result @@ -95,7 +109,8 @@ def wrap_web_tests_adapter(): def get_app(self): self.app = Application(self.get_handlers(), **self.get_app_kwargs()) - return WSGIContainer(validator(WSGIAdapter(self.app))) + with ignore_deprecation(): + return WSGIContainer(validator(WSGIAdapter(self.app))) result["WSGIAdapter_" + cls.__name__] = WSGIAdapterWrappedTest return result diff --git a/tornado/wsgi.py b/tornado/wsgi.py index 22be7a897..892c0a929 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -33,6 +33,7 @@ from __future__ import absolute_import, division, print_function import sys from io import BytesIO import tornado +import warnings from tornado.concurrent import Future from tornado import escape @@ -76,6 +77,7 @@ class WSGIApplication(web.Application): .. deprecated:: 4.0 Use a regular `.Application` and wrap it in `WSGIAdapter` instead. + This class will be removed in Tornado 6.0. """ def __call__(self, environ, start_response): return WSGIAdapter(self)(environ, start_response) @@ -180,8 +182,15 @@ class WSGIAdapter(object): `tornado.auth` or `tornado.websocket` modules. .. versionadded:: 4.0 + + .. deprecated:: 5.1 + + This class is deprecated and will be removed in Tornado 6.0. + Use Tornado's `.HTTPServer` instead of a WSGI container. """ def __init__(self, application): + warnings.warn("WSGIAdapter is deprecated, use Tornado's HTTPServer instead", + DeprecationWarning) if isinstance(application, WSGIApplication): self.application = lambda request: web.Application.__call__( application, request)