]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
wsgi: Deprecate WSGIAdapter and WSGIApplication
authorBen Darnell <ben@bendarnell.com>
Sat, 5 May 2018 18:10:33 +0000 (14:10 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 5 May 2018 18:10:33 +0000 (14:10 -0400)
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

tornado/test/wsgi_test.py
tornado/wsgi.py

index e6ccc82ae0c8c63d4c04d8966f7375f87e5d362c..d32140f8b0f99c425a7d36fa27ad010d05ea95a2 100644 (file)
@@ -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
 
index 22be7a897235080ac5805bb9cf638ab4a7d9af77..892c0a929fa8544ae6bfe6c89724f2a060dc873f 100644 (file)
@@ -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)