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