本文整理汇总了Python中tornado.web.Finish方法的典型用法代码示例。如果您正苦于以下问题:Python web.Finish方法的具体用法?Python web.Finish怎么用?Python web.Finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.web
的用法示例。
在下文中一共展示了web.Finish方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import Finish [as 别名]
def get(self):
self.set_status(401)
self.set_header('WWW-Authenticate', 'Basic realm="something"')
if self.get_argument('finish_value', ''):
raise Finish('authentication required')
else:
self.write('authentication required')
raise Finish()
示例2: cursor
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import Finish [as 别名]
def cursor(self):
cursor = self.get_argument('cursor', None)
if cursor:
try:
cursor = int(cursor)
except ValueError:
self.redirect(self.request.path, permanent=True)
raise Finish()
if cursor < 0:
raise HTTPError(404)
else:
cursor = None
return cursor
示例3: emit
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import Finish [as 别名]
def emit(self, data):
"""Emit an eventstream event"""
if type(data) is not str:
serialized_data = json.dumps(data)
else:
serialized_data = data
try:
self.write('data: {}\n\n'.format(serialized_data))
await self.flush()
except StreamClosedError:
app_log.warning("Stream closed while handling %s", self.request.uri)
# raise Finish to halt the handler
raise Finish()
示例4: call
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import Finish [as 别名]
def call(self, module, method, wrapped, instance, args, kwargs):
if not hasattr(instance.application, "elasticapm_client"):
# If tornado was instrumented but not as the main framework
# (i.e. in Flower), we should skip it.
return wrapped(*args, **kwargs)
# Late import to avoid ImportErrors
from tornado.web import Finish, HTTPError
from elasticapm.contrib.tornado.utils import get_data_from_request
e = args[0]
if isinstance(e, Finish):
# Not an error; Finish is an exception that ends a request without an error response
return wrapped(*args, **kwargs)
client = instance.application.elasticapm_client
request = instance.request
client.capture_exception(
context={"request": get_data_from_request(instance, request, client.config, constants.ERROR)}
)
if isinstance(e, HTTPError):
elasticapm.set_transaction_result("HTTP {}xx".format(int(e.status_code / 100)), override=False)
elasticapm.set_context({"status_code": e.status_code}, "response")
else:
elasticapm.set_transaction_result("HTTP 5xx", override=False)
elasticapm.set_context({"status_code": 500}, "response")
return wrapped(*args, **kwargs)
示例5: _raise_auth_required
# 需要导入模块: from tornado import web [as 别名]
# 或者: from tornado.web import Finish [as 别名]
def _raise_auth_required(self):
from tornado import web
self.set_status(401)
self.write("Authentication required")
self.set_header("WWW-Authenticate", "Negotiate")
raise web.Finish()