Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
tornadoweb
Tornado
提交
0e43388c
Tornado
项目概览
镜像
/
tornadoweb
/
Tornado
12 个月 前同步成功
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Tornado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0e43388c
编写于
3月 18, 2018
作者:
B
Ben Darnell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gen: Deprecate gen.engine
上级
eecf05f0
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
119 addition
and
115 deletion
+119
-115
tornado/gen.py
tornado/gen.py
+8
-0
tornado/test/auth_test.py
tornado/test/auth_test.py
+27
-54
tornado/test/concurrent_test.py
tornado/test/concurrent_test.py
+29
-15
tornado/test/gen_test.py
tornado/test/gen_test.py
+34
-26
tornado/test/stack_context_test.py
tornado/test/stack_context_test.py
+20
-18
tornado/test/web_test.py
tornado/test/web_test.py
+1
-2
未找到文件。
tornado/gen.py
浏览文件 @
0e43388c
...
...
@@ -96,6 +96,7 @@ import itertools
import
os
import
sys
import
types
import
warnings
from
tornado.concurrent
import
(
Future
,
is_future
,
chain_future
,
future_set_exc_info
,
future_add_done_callback
,
future_set_result_unless_cancelled
)
...
...
@@ -213,7 +214,14 @@ def engine(func):
they are finished. One notable exception is the
`~tornado.web.RequestHandler` :ref:`HTTP verb methods <verbs>`,
which use ``self.finish()`` in place of a callback argument.
.. deprecated:: 5.1
This decorator will be removed in 6.0. Use `coroutine` or
``async def`` instead.
"""
warnings
.
warn
(
"gen.engine is deprecated, use gen.coroutine or async def instead"
,
DeprecationWarning
)
func
=
_make_coroutine_wrapper
(
func
,
replace_callback
=
False
)
@
functools
.
wraps
(
func
)
...
...
tornado/test/auth_test.py
浏览文件 @
0e43388c
...
...
@@ -252,6 +252,7 @@ class TwitterClientLoginHandler(TwitterClientHandler):
class
TwitterClientLoginGenEngineHandler
(
TwitterClientHandler
):
with
ignore_deprecation
():
@
asynchronous
@
gen
.
engine
def
get
(
self
):
...
...
@@ -277,6 +278,7 @@ class TwitterClientLoginGenCoroutineHandler(TwitterClientHandler):
class
TwitterClientShowUserHandlerLegacy
(
TwitterClientHandler
):
with
ignore_deprecation
():
@
asynchronous
@
gen
.
engine
def
get
(
self
):
...
...
@@ -310,22 +312,6 @@ class TwitterClientShowUserHandler(TwitterClientHandler):
self
.
finish
(
response
)
class
TwitterClientShowUserFutureHandler
(
TwitterClientHandler
):
@
asynchronous
@
gen
.
engine
def
get
(
self
):
try
:
response
=
yield
self
.
twitter_request
(
'/users/show/%s'
%
self
.
get_argument
(
'name'
),
access_token
=
dict
(
key
=
'hjkl'
,
secret
=
'vbnm'
))
except
AuthError
as
e
:
self
.
set_status
(
500
)
self
.
finish
(
str
(
e
))
return
assert
response
is
not
None
self
.
finish
(
response
)
class
TwitterServerAccessTokenHandler
(
RequestHandler
):
def
get
(
self
):
self
.
write
(
'oauth_token=hjkl&oauth_token_secret=vbnm&screen_name=foo'
)
...
...
@@ -395,8 +381,6 @@ class AuthTest(AsyncHTTPTestCase):
TwitterClientShowUserHandlerLegacy
,
dict
(
test
=
self
)),
(
'/twitter/client/show_user'
,
TwitterClientShowUserHandler
,
dict
(
test
=
self
)),
(
'/twitter/client/show_user_future'
,
TwitterClientShowUserFutureHandler
,
dict
(
test
=
self
)),
# simulated servers
(
'/openid/server/authenticate'
,
OpenIdServerAuthenticateHandler
),
...
...
@@ -623,17 +607,6 @@ class AuthTest(AsyncHTTPTestCase):
self
.
assertEqual
(
response
.
code
,
500
)
self
.
assertEqual
(
response
.
body
,
b
'error from twitter request'
)
def
test_twitter_show_user_future
(
self
):
response
=
self
.
fetch
(
'/twitter/client/show_user_future?name=somebody'
)
response
.
rethrow
()
self
.
assertEqual
(
json_decode
(
response
.
body
),
{
'name'
:
'Somebody'
,
'screen_name'
:
'somebody'
})
def
test_twitter_show_user_future_error
(
self
):
response
=
self
.
fetch
(
'/twitter/client/show_user_future?name=error'
)
self
.
assertEqual
(
response
.
code
,
500
)
self
.
assertIn
(
b
'Error response HTTP 500'
,
response
.
body
)
class
GoogleLoginHandler
(
RequestHandler
,
GoogleOAuth2Mixin
):
def
initialize
(
self
,
test
):
...
...
tornado/test/concurrent_test.py
浏览文件 @
0e43388c
...
...
@@ -178,7 +178,8 @@ class ReturnFutureTest(AsyncTestCase):
future
.
result
()
@
gen_test
def
test_future_traceback
(
self
):
def
test_future_traceback_legacy
(
self
):
with
ignore_deprecation
():
@
return_future
@
gen
.
engine
def
f
(
callback
):
...
...
@@ -196,6 +197,24 @@ class ReturnFutureTest(AsyncTestCase):
tb
=
traceback
.
extract_tb
(
sys
.
exc_info
()[
2
])
self
.
assertIn
(
self
.
expected_frame
,
tb
)
@
gen_test
def
test_future_traceback
(
self
):
@
gen
.
coroutine
def
f
():
yield
gen
.
Task
(
self
.
io_loop
.
add_callback
)
try
:
1
/
0
except
ZeroDivisionError
:
self
.
expected_frame
=
traceback
.
extract_tb
(
sys
.
exc_info
()[
2
],
limit
=
1
)[
0
]
raise
try
:
yield
f
()
self
.
fail
(
"didn't get expected exception"
)
except
ZeroDivisionError
:
tb
=
traceback
.
extract_tb
(
sys
.
exc_info
()[
2
])
self
.
assertIn
(
self
.
expected_frame
,
tb
)
@
gen_test
def
test_uncaught_exception_log
(
self
):
if
IOLoop
.
configured_class
().
__name__
.
endswith
(
'AsyncIOLoop'
):
...
...
@@ -311,9 +330,8 @@ class DecoratorCapClient(BaseCapClient):
class
GeneratorCapClient
(
BaseCapClient
):
@
return_future
@
gen
.
engine
def
capitalize
(
self
,
request_data
,
callback
):
@
gen
.
coroutine
def
capitalize
(
self
,
request_data
):
logging
.
debug
(
'capitalize'
)
stream
=
IOStream
(
socket
.
socket
())
logging
.
debug
(
'connecting'
)
...
...
@@ -323,7 +341,7 @@ class GeneratorCapClient(BaseCapClient):
data
=
yield
gen
.
Task
(
stream
.
read_until
,
b
'
\n
'
)
logging
.
debug
(
'returning'
)
stream
.
close
()
callback
(
self
.
process_response
(
data
))
raise
gen
.
Return
(
self
.
process_response
(
data
))
class
ClientTestMixin
(
object
):
...
...
@@ -362,22 +380,18 @@ class ClientTestMixin(object):
self
.
assertRaisesRegexp
(
CapError
,
"already capitalized"
,
future
.
result
)
def
test_generator
(
self
):
@
gen
.
eng
ine
@
gen
.
corout
ine
def
f
():
result
=
yield
self
.
client
.
capitalize
(
"hello"
)
self
.
assertEqual
(
result
,
"HELLO"
)
self
.
stop
()
f
()
self
.
wait
()
self
.
io_loop
.
run_sync
(
f
)
def
test_generator_error
(
self
):
@
gen
.
eng
ine
@
gen
.
corout
ine
def
f
():
with
self
.
assertRaisesRegexp
(
CapError
,
"already capitalized"
):
yield
self
.
client
.
capitalize
(
"HELLO"
)
self
.
stop
()
f
()
self
.
wait
()
self
.
io_loop
.
run_sync
(
f
)
class
ManualClientTest
(
ClientTestMixin
,
AsyncTestCase
):
...
...
tornado/test/gen_test.py
浏览文件 @
0e43388c
...
...
@@ -9,6 +9,7 @@ import sys
import
textwrap
import
time
import
weakref
import
warnings
from
tornado.concurrent
import
return_future
,
Future
from
tornado.escape
import
url_escape
...
...
@@ -17,7 +18,7 @@ from tornado.ioloop import IOLoop
from
tornado.log
import
app_log
from
tornado
import
stack_context
from
tornado.testing
import
AsyncHTTPTestCase
,
AsyncTestCase
,
ExpectLog
,
gen_test
from
tornado.test.util
import
unittest
,
skipOnTravis
,
skipBefore33
,
skipBefore35
,
skipNotCPython
,
exec_test
# noqa: E501
from
tornado.test.util
import
unittest
,
skipOnTravis
,
skipBefore33
,
skipBefore35
,
skipNotCPython
,
exec_test
,
ignore_deprecation
# noqa: E501
from
tornado.web
import
Application
,
RequestHandler
,
asynchronous
,
HTTPError
from
tornado
import
gen
...
...
@@ -35,9 +36,16 @@ except ImportError:
class
GenEngineTest
(
AsyncTestCase
):
def
setUp
(
self
):
self
.
warning_catcher
=
warnings
.
catch_warnings
()
self
.
warning_catcher
.
__enter__
()
warnings
.
simplefilter
(
'ignore'
,
DeprecationWarning
)
super
(
GenEngineTest
,
self
).
setUp
()
self
.
named_contexts
=
[]
def
tearDown
(
self
):
super
(
GenEngineTest
,
self
).
tearDown
()
self
.
warning_catcher
.
__exit__
(
None
,
None
,
None
)
def
named_context
(
self
,
name
):
@
contextlib
.
contextmanager
def
context
():
...
...
@@ -1085,6 +1093,7 @@ class GenCoroutineTest(AsyncTestCase):
class
GenSequenceHandler
(
RequestHandler
):
with
ignore_deprecation
():
@
asynchronous
@
gen
.
engine
def
get
(
self
):
...
...
@@ -1136,8 +1145,7 @@ class GenCoroutineUnfinishedSequenceHandler(RequestHandler):
class
GenTaskHandler
(
RequestHandler
):
@
asynchronous
@
gen
.
engine
@
gen
.
coroutine
def
get
(
self
):
client
=
AsyncHTTPClient
()
response
=
yield
gen
.
Task
(
client
.
fetch
,
self
.
get_argument
(
'url'
))
...
...
@@ -1146,6 +1154,7 @@ class GenTaskHandler(RequestHandler):
class
GenExceptionHandler
(
RequestHandler
):
with
ignore_deprecation
():
@
asynchronous
@
gen
.
engine
def
get
(
self
):
...
...
@@ -1165,8 +1174,7 @@ class GenCoroutineExceptionHandler(RequestHandler):
class
GenYieldExceptionHandler
(
RequestHandler
):
@
asynchronous
@
gen
.
engine
@
gen
.
coroutine
def
get
(
self
):
io_loop
=
self
.
request
.
connection
.
stream
.
io_loop
# Test the interaction of the two stack_contexts.
...
...
tornado/test/stack_context_test.py
浏览文件 @
0e43388c
...
...
@@ -6,7 +6,7 @@ from tornado.log import app_log
from
tornado.stack_context
import
(
StackContext
,
wrap
,
NullContext
,
StackContextInconsistentError
,
ExceptionStackContext
,
run_with_stack_context
,
_state
)
from
tornado.testing
import
AsyncHTTPTestCase
,
AsyncTestCase
,
ExpectLog
,
gen_test
from
tornado.test.util
import
unittest
from
tornado.test.util
import
unittest
,
ignore_deprecation
from
tornado.web
import
asynchronous
,
Application
,
RequestHandler
import
contextlib
import
functools
...
...
@@ -215,6 +215,7 @@ class StackContextTest(AsyncTestCase):
self
.
wait
()
def
test_yield_in_with
(
self
):
with
ignore_deprecation
():
@
gen
.
engine
def
f
():
self
.
callback
=
yield
gen
.
Callback
(
'a'
)
...
...
@@ -244,6 +245,7 @@ class StackContextTest(AsyncTestCase):
def
test_yield_in_with_exception_stack_context
(
self
):
# As above, but with ExceptionStackContext instead of StackContext.
with
ignore_deprecation
():
@
gen
.
engine
def
f
():
with
ExceptionStackContext
(
lambda
t
,
v
,
tb
:
False
):
...
...
tornado/test/web_test.py
浏览文件 @
0e43388c
...
...
@@ -582,8 +582,7 @@ class RedirectHandler(RequestHandler):
class
EmptyFlushCallbackHandler
(
RequestHandler
):
@
asynchronous
@
gen
.
engine
@
gen
.
coroutine
def
get
(
self
):
# Ensure that the flush callback is run whether or not there
# was any output. The gen.Task and direct yield forms are
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录