本文整理汇总了Python中flask.request._get_current_object方法的典型用法代码示例。如果您正苦于以下问题:Python request._get_current_object方法的具体用法?Python request._get_current_object怎么用?Python request._get_current_object使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.request
的用法示例。
在下文中一共展示了request._get_current_object方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_worker
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import _get_current_object [as 别名]
def get_worker():
try:
return request._get_current_object()
except RuntimeError:
return None
示例2: _before_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import _get_current_object [as 别名]
def _before_request(self):
headers = request.headers
xray_header = construct_xray_header(headers)
req = request._get_current_object()
name = calculate_segment_name(req.host, self._recorder)
sampling_req = {
'host': req.host,
'method': req.method,
'path': req.path,
'service': name,
}
sampling_decision = calculate_sampling_decision(
trace_header=xray_header,
recorder=self._recorder,
sampling_req=sampling_req,
)
if self.in_lambda_ctx:
segment = self._recorder.begin_subsegment(name)
else:
segment = self._recorder.begin_segment(
name=name,
traceid=xray_header.root,
parent_id=xray_header.parent,
sampling=sampling_decision,
)
segment.save_origin_trace_header(xray_header)
segment.put_http_meta(http.URL, req.base_url)
segment.put_http_meta(http.METHOD, req.method)
segment.put_http_meta(http.USER_AGENT, headers.get('User-Agent'))
client_ip = headers.get('X-Forwarded-For') or headers.get('HTTP_X_FORWARDED_FOR')
if client_ip:
segment.put_http_meta(http.CLIENT_IP, client_ip)
segment.put_http_meta(http.X_FORWARDED_FOR, True)
else:
segment.put_http_meta(http.CLIENT_IP, req.remote_addr)
示例3: get_worker
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import _get_current_object [as 别名]
def get_worker():
try:
return request._get_current_object()
except RuntimeError:
return None
示例4: get_session
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import _get_current_object [as 别名]
def get_session(self):
ctx = request._get_current_object()
try:
session = ctx._current_session
except AttributeError:
return None
else:
return session
示例5: is_browser
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import _get_current_object [as 别名]
def is_browser():
"""Is the current request from a browser?"""
# all subrequests are not from browsers
if hasattr(request._get_current_object(), 'is_subrequest') and request.is_subrequest:
return False
best_match = request.accept_mimetypes.best_match(_mime_types)
return best_match == 'text/html'