當前位置: 首頁>>代碼示例>>Python>>正文


Python request._get_current_object方法代碼示例

本文整理匯總了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 
開發者ID:jmcarp,項目名稱:nplusone,代碼行數:7,代碼來源:flask_sqlalchemy.py

示例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) 
開發者ID:aws,項目名稱:aws-xray-sdk-python,代碼行數:42,代碼來源:middleware.py

示例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 
開發者ID:getsentry,項目名稱:zeus,代碼行數:8,代碼來源:nplusone.py

示例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 
開發者ID:spoqa,項目名稱:dodotable,代碼行數:10,代碼來源:flask.py

示例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' 
開發者ID:mozilla,項目名稱:build-relengapi,代碼行數:9,代碼來源:__init__.py


注:本文中的flask.request._get_current_object方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。