本文整理匯總了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()