提交 c60ab672 编写于 作者: B Ben Darnell

web: Deprecate asynchronous decorator

上级 0200fc85
......@@ -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:
......
......@@ -1368,7 +1368,6 @@ class GenCoroutineSequenceHandler(RequestHandler):
class GenCoroutineUnfinishedSequenceHandler(RequestHandler):
@asynchronous
@gen.coroutine
def get(self):
yield gen.moment
......
......@@ -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
......
......@@ -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):
......
......@@ -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()')
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册