当前位置: 首页>>代码示例>>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;未经允许,请勿转载。