]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
web: Deprecate asynchronous decorator
authorBen Darnell <ben@bendarnell.com>
Fri, 27 Apr 2018 14:36:51 +0000 (10:36 -0400)
committerBen Darnell <ben@bendarnell.com>
Fri, 27 Apr 2018 14:36:51 +0000 (10:36 -0400)
tornado/test/auth_test.py
tornado/test/gen_test.py
tornado/test/httpserver_test.py
tornado/test/simple_httpclient_test.py
tornado/test/stack_context_test.py
tornado/test/web_test.py
tornado/web.py

index 0d26a35afc92fcfb627da52a66266ecf78b2689c..e0fd437b15f8e3b08d54db4d7a5ef21e33af6729 100644 (file)
@@ -26,17 +26,18 @@ class OpenIdClientLoginHandlerLegacy(RequestHandler, OpenIdMixin):
     def initialize(self, test):
         self._OPENID_ENDPOINT = test.get_url('/openid/server/authenticate')
 
-    @asynchronous
-    def get(self):
-        if self.get_argument('openid.mode', None):
-            with warnings.catch_warnings():
-                warnings.simplefilter('ignore', DeprecationWarning)
-                self.get_authenticated_user(
-                    self.on_user, http_client=self.settings['http_client'])
-                return
-        res = self.authenticate_redirect()
-        assert isinstance(res, Future)
-        assert res.done()
+    with ignore_deprecation():
+        @asynchronous
+        def get(self):
+            if self.get_argument('openid.mode', None):
+                with warnings.catch_warnings():
+                    warnings.simplefilter('ignore', DeprecationWarning)
+                    self.get_authenticated_user(
+                        self.on_user, http_client=self.settings['http_client'])
+                    return
+            res = self.authenticate_redirect()
+            assert isinstance(res, Future)
+            assert res.done()
 
     def on_user(self, user):
         if user is None:
@@ -78,16 +79,17 @@ class OAuth1ClientLoginHandlerLegacy(RequestHandler, OAuthMixin):
     def _oauth_consumer_token(self):
         return dict(key='asdf', secret='qwer')
 
-    @asynchronous
-    def get(self):
-        if self.get_argument('oauth_token', None):
-            with warnings.catch_warnings():
-                warnings.simplefilter('ignore', DeprecationWarning)
-                self.get_authenticated_user(
-                    self.on_user, http_client=self.settings['http_client'])
-            return
-        res = self.authorize_redirect(http_client=self.settings['http_client'])
-        assert isinstance(res, Future)
+    with ignore_deprecation():
+        @asynchronous
+        def get(self):
+            if self.get_argument('oauth_token', None):
+                with warnings.catch_warnings():
+                    warnings.simplefilter('ignore', DeprecationWarning)
+                    self.get_authenticated_user(
+                        self.on_user, http_client=self.settings['http_client'])
+                return
+            res = self.authorize_redirect(http_client=self.settings['http_client'])
+            assert isinstance(res, Future)
 
     def on_user(self, user):
         if user is None:
@@ -226,12 +228,13 @@ class TwitterClientHandler(RequestHandler, TwitterMixin):
 
 
 class TwitterClientLoginHandlerLegacy(TwitterClientHandler):
-    @asynchronous
-    def get(self):
-        if self.get_argument("oauth_token", None):
-            self.get_authenticated_user(self.on_user)
-            return
-        self.authorize_redirect()
+    with ignore_deprecation():
+        @asynchronous
+        def get(self):
+            if self.get_argument("oauth_token", None):
+                self.get_authenticated_user(self.on_user)
+                return
+            self.authorize_redirect()
 
     def on_user(self, user):
         if user is None:
index 8b2f62b9728acbc9254f535689de56a2585d6db1..721d927dd4edf08e96e119723a943c4a5906056a 100644 (file)
@@ -1368,7 +1368,6 @@ class GenCoroutineSequenceHandler(RequestHandler):
 
 
 class GenCoroutineUnfinishedSequenceHandler(RequestHandler):
-    @asynchronous
     @gen.coroutine
     def get(self):
         yield gen.moment
index 4bca757a66883c0084376f8a47a416f5e2ea05b8..5abb7fe3c82bacd439cae818cd65d7abe5d0b893 100644 (file)
@@ -14,7 +14,7 @@ from tornado.netutil import ssl_options_to_context
 from tornado.simple_httpclient import SimpleAsyncHTTPClient
 from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog, gen_test  # noqa: E501
 from tornado.test.util import unittest, skipOnTravis, ignore_deprecation
-from tornado.web import Application, RequestHandler, asynchronous, stream_request_body
+from tornado.web import Application, RequestHandler, stream_request_body
 
 from contextlib import closing
 import datetime
@@ -668,9 +668,11 @@ class KeepAliveTest(AsyncHTTPTestCase):
                 self.write(''.join(chr(i % 256) * 1024 for i in range(512)))
 
         class FinishOnCloseHandler(RequestHandler):
-            @asynchronous
+            @gen.coroutine
             def get(self):
                 self.flush()
+                never_finish = Event()
+                yield never_finish.wait()
 
             def on_connection_close(self):
                 # This is not very realistic, but finishing the request
index 09038710dc09fd2e04dbed24bd94d22c081dd9c9..378c13d34fe169d9b351bd87a2512343247aef52 100644 (file)
@@ -17,6 +17,7 @@ from tornado.httpclient import AsyncHTTPClient
 from tornado.httputil import HTTPHeaders, ResponseStartLine
 from tornado.ioloop import IOLoop
 from tornado.iostream import UnsatisfiableReadError
+from tornado.locks import Event
 from tornado.log import gen_log
 from tornado.concurrent import Future
 from tornado.netutil import Resolver, bind_sockets
@@ -27,7 +28,7 @@ from tornado.testing import (AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCas
                              ExpectLog, gen_test)
 from tornado.test.util import (skipOnTravis, skipIfNoIPv6, refusing_port, skipBefore35,
                                exec_test, ignore_deprecation)
-from tornado.web import RequestHandler, Application, asynchronous, url, stream_request_body
+from tornado.web import RequestHandler, Application, url, stream_request_body
 
 
 class SimpleHTTPClientCommonTestCase(httpclient_test.HTTPClientCommonTestCase):
@@ -42,18 +43,21 @@ class TriggerHandler(RequestHandler):
         self.queue = queue
         self.wake_callback = wake_callback
 
-    @asynchronous
+    @gen.coroutine
     def get(self):
         logging.debug("queuing trigger")
         self.queue.append(self.finish)
         if self.get_argument("wake", "true") == "true":
             self.wake_callback()
+        never_finish = Event()
+        yield never_finish.wait()
 
 
 class HangHandler(RequestHandler):
-    @asynchronous
+    @gen.coroutine
     def get(self):
-        pass
+        never_finish = Event()
+        yield never_finish.wait()
 
 
 class ContentLengthHandler(RequestHandler):
index 243ea47f3a0ee540f142f87d535db7dccfccebdd..61411d2ff68cb1639ce29275983bea9c5a680800 100644 (file)
@@ -18,12 +18,13 @@ class TestRequestHandler(RequestHandler):
     def __init__(self, app, request):
         super(TestRequestHandler, self).__init__(app, request)
 
-    @asynchronous
-    def get(self):
-        logging.debug('in get()')
-        # call self.part2 without a self.async_callback wrapper.  Its
-        # exception should still get thrown
-        IOLoop.current().add_callback(self.part2)
+    with ignore_deprecation():
+        @asynchronous
+        def get(self):
+            logging.debug('in get()')
+            # call self.part2 without a self.async_callback wrapper.  Its
+            # exception should still get thrown
+            IOLoop.current().add_callback(self.part2)
 
     def part2(self):
         logging.debug('in part2()')
index 7f053ef063af8deabb18853e7af722bec4483695..b318fb17622a75d166004bbe6773753ccd571a14 100644 (file)
@@ -8,6 +8,7 @@ from tornado.httputil import format_timestamp
 from tornado.ioloop import IOLoop
 from tornado.iostream import IOStream
 from tornado import locale
+from tornado.locks import Event
 from tornado.log import app_log, gen_log
 from tornado.simple_httpclient import SimpleAsyncHTTPClient
 from tornado.template import DictLoader
@@ -369,9 +370,11 @@ class ConnectionCloseHandler(RequestHandler):
     def initialize(self, test):
         self.test = test
 
-    @asynchronous
+    @gen.coroutine
     def get(self):
         self.test.on_handler_waiting()
+        never_finish = Event()
+        yield never_finish.wait()
 
     def on_connection_close(self):
         self.test.on_connection_close()
@@ -548,10 +551,11 @@ class OptionalPathHandler(RequestHandler):
 class FlowControlHandler(RequestHandler):
     # These writes are too small to demonstrate real flow control,
     # but at least it shows that the callbacks get run.
-    @asynchronous
-    def get(self):
-        self.write("1")
-        self.flush(callback=self.step2)
+    with ignore_deprecation():
+        @asynchronous
+        def get(self):
+            self.write("1")
+            self.flush(callback=self.step2)
 
     def step2(self):
         self.write("2")
@@ -1805,10 +1809,11 @@ class MultipleExceptionTest(SimpleHandlerTestCase):
     class Handler(RequestHandler):
         exc_count = 0
 
-        @asynchronous
-        def get(self):
-            IOLoop.current().add_callback(lambda: 1 / 0)
-            IOLoop.current().add_callback(lambda: 1 / 0)
+        with ignore_deprecation():
+            @asynchronous
+            def get(self):
+                IOLoop.current().add_callback(lambda: 1 / 0)
+                IOLoop.current().add_callback(lambda: 1 / 0)
 
         def log_exception(self, typ, value, tb):
             MultipleExceptionTest.Handler.exc_count += 1
index 888dc543138f2b4e65b48a33d5a1b4ddd9752233..6693f10c5ef28c7255d2dfffa27771e80b79143b 100644 (file)
@@ -78,6 +78,7 @@ import time
 import tornado
 import traceback
 import types
+import warnings
 from inspect import isclass
 from io import BytesIO
 
@@ -1702,7 +1703,14 @@ def asynchronous(method):
     .. versionchanged:: 4.3 Returning anything but ``None`` or a
        yieldable object from a method decorated with ``@asynchronous``
        is an error. Such return values were previously ignored silently.
+
+    .. deprecated:: 5.1
+
+       This decorator is deprecated and will be removed in Tornado 6.0.
+       Use coroutines instead.
     """
+    warnings.warn("@asynchronous is deprecated, use coroutines instead",
+                  DeprecationWarning)
     # Delay the IOLoop import because it's not available on app engine.
     from tornado.ioloop import IOLoop