当前位置: 首页>>代码示例>>Python>>正文


Python _request_ctx_stack.top方法代码示例

本文整理汇总了Python中flask._request_ctx_stack.top方法的典型用法代码示例。如果您正苦于以下问题:Python _request_ctx_stack.top方法的具体用法?Python _request_ctx_stack.top怎么用?Python _request_ctx_stack.top使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask._request_ctx_stack的用法示例。


在下文中一共展示了_request_ctx_stack.top方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_translations

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def _get_translations():
    """Returns the correct gettext translations.
    Copy from flask-babel with some modifications.
    """
    ctx = _request_ctx_stack.top
    if ctx is None:
        return None
    # babel should be in extensions for get_locale
    if 'babel' not in ctx.app.extensions:
        return None
    translations = getattr(ctx, 'wtforms_translations', None)
    if translations is None:
        dirname = messages_path()
        translations = support.Translations.load(
            dirname, [get_locale()], domain='wtforms'
        )
        ctx.wtforms_translations = translations
    return translations 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:i18n.py

示例2: _contextualise_connection

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def _contextualise_connection(self, connection):
        """
        Add a connection to the appcontext so it can be freed/unbound at
        a later time if an exception occured and it was not freed.

        Args:
            connection (ldap3.Connection): Connection to add to the appcontext

        """

        ctx = stack.top
        if ctx is not None:
            if not hasattr(ctx, "ldap3_manager_connections"):
                ctx.ldap3_manager_connections = [connection]
            else:
                ctx.ldap3_manager_connections.append(connection) 
开发者ID:nickw444,项目名称:flask-ldap3-login,代码行数:18,代码来源:__init__.py

示例3: _after_request_fn

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def _after_request_fn(self, response=None, error=None):
        request = stack.top.request

        # the pop call can fail if the request is interrupted by a
        # `before_request` method so we need a default
        scope = self._current_scopes.pop(request, None)
        if scope is None:
            return

        if response is not None:
            scope.span.set_tag(tags.HTTP_STATUS_CODE, response.status_code)
        if error is not None:
            scope.span.set_tag(tags.ERROR, True)
            scope.span.log_kv({
                'event': tags.ERROR,
                'error.object': error,
            })

        scope.close() 
开发者ID:opentracing-contrib,项目名称:python-flask,代码行数:21,代码来源:tracing.py

示例4: _jwt_required

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def _jwt_required(realm):
    """Does the actual work of verifying the JWT data in the current request.
    This is done automatically for you by `jwt_required()` but you could call it manually.
    Doing so would be useful in the context of optional JWT access in your APIs.

    :param realm: an optional realm
    """
    token = _jwt.request_callback()

    if token is None:
        raise JWTError('Authorization Required', 'Request does not contain an access token',
                       headers={'WWW-Authenticate': 'JWT realm="%s"' % realm})

    try:
        payload = _jwt.jwt_decode_callback(token)
    except jwt.InvalidTokenError as e:
        raise JWTError('Invalid token', str(e))

    _request_ctx_stack.top.current_identity = identity = _jwt.identity_callback(payload)

    if identity is None:
        raise JWTError('Invalid JWT', 'User does not exist') 
开发者ID:mattupstate,项目名称:flask-jwt,代码行数:24,代码来源:__init__.py

示例5: getContacts

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def getContacts(self, num=1, columns=[], cardCode=None, contact={}):
        """Retrieve contacts under a business partner by CardCode from SAP B1.
        """
        cols = '*'
        if len(columns) > 0:
            cols = " ,".join(columns)

        sql = """SELECT top {0} {1} FROM dbo.OCPR""".format(num, cols)
        params = dict({(k, 'null' if v is None else v) for k, v in contact.items()})
        params['cardcode'] = cardCode
        sql = sql + ' WHERE ' + " AND ".join(["{0} = %({1})s".format(k, k) for k in params.keys()])

        self.cursorAdaptor.sqlSrvCursor.execute(sql, params)
        contacts = []
        for row in self.cursorAdaptor.sqlSrvCursor:
            contact = {}
            for k, v in row.items():
                value = ''
                if type(v) is datetime.datetime:
                    value = v.strftime("%Y-%m-%d %H:%M:%S")
                elif v is not None:
                    value = str(v)
                contact[k] = value
            contacts.append(contact)
        return contacts 
开发者ID:ideabosque,项目名称:Flask-SAPB1,代码行数:27,代码来源:flask_sapb1.py

示例6: banner

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def banner(self, text, ch='=', side='-', width=None):
        """
        Surrounds the text with an ascii banner:

            ========================================
            -             Hello World!             -
            ========================================
        """
        width = width or self.default_width
        offset = len(side)
        lines = []
        for line in text.splitlines():
            if side:
                lines.append(side + line.center(width)[offset:-offset] + side)
            else:
                lines.append(line.center(width))
        if ch:
            # Add the top & bottom
            top = bottom = (ch * width)[:width]
            lines = [top] + lines + [bottom]
        return '\r\n'.join(lines) 
开发者ID:michael-lazar,项目名称:flask-gopher,代码行数:23,代码来源:flask_gopher.py

示例7: float_right

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def float_right(self, text_left, text_right, fillchar=' ', width=None):
        """
        Left-justifies text, and then overlays right justified text on top
        of it. This gives the effect of having a floating div on both
        sides of the screen.
        """
        width = width or self.default_width
        left_lines = text_left.splitlines()
        right_lines = text_right.splitlines()

        lines = []
        for left, right in zip_longest(left_lines, right_lines, fillvalue=''):
            padding = width - len(right)
            line = (left.ljust(padding, fillchar) + right)[-width:]
            lines.append(line)
        return '\r\n'.join(lines) 
开发者ID:michael-lazar,项目名称:flask-gopher,代码行数:18,代码来源:flask_gopher.py

示例8: push_ctx

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def push_ctx(app=None):
    """Creates new test context(s) for the given app

    If the app is not None, it overrides any existing app and/or request
    context. In other words, we will use the app that was passed in to create
    a new test request context on the top of the stack. If, however, nothing
    was passed in, we will assume that another app and/or  request context is
    already in place and use that to run the test suite. If no app or request
    context can be found, an AssertionError is emitted to let the user know
    that they must somehow specify an application for testing.

    """
    if app is not None:
        ctx = app.test_request_context()
        ctx.fixtures_request_context = True
        ctx.push()
        if _app_ctx_stack is not None:
            _app_ctx_stack.top.fixtures_app_context = True

    # Make sure that we have an application in the current context
    if (_app_ctx_stack is None or _app_ctx_stack.top is None) and _request_ctx_stack.top is None:
        raise AssertionError('A Flask application must be specified for Fixtures to work.') 
开发者ID:croach,项目名称:Flask-Fixtures,代码行数:24,代码来源:__init__.py

示例9: __exit__

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def __exit__(self, exc_type, exc_value, tb):
        self.preserve_context = False

        # on exit we want to clean up earlier.  Normally the request context
        # stays preserved until the next request in the same thread comes
        # in.  See RequestGlobals.push() for the general behavior.
        top = _request_ctx_stack.top
        if top is not None and top.preserved:
            top.pop() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:testing.py

示例10: teardown_request

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def teardown_request(self, exception):
        ctx = _ctx_stack.top
        if hasattr(ctx, "mysql_db"):
            ctx.mysql_db.close() 
开发者ID:LuciferJack,项目名称:python-mysql-pool,代码行数:6,代码来源:mysql.py

示例11: get_db

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def get_db(self):
        ctx = _ctx_stack.top
        if ctx is not None:
            if not hasattr(ctx, "mysql_db"):
                ctx.mysql_db = self.connect()
            return ctx.mysql_db 
开发者ID:LuciferJack,项目名称:python-mysql-pool,代码行数:8,代码来源:mysql.py

示例12: get_raw_jwt

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def get_raw_jwt():
    """
    In a protected endpoint, this will return the python dictionary which has
    all of the claims of the JWT that is accessing the endpoint. If no
    JWT is currently present, an empty dict is returned instead.
    """
    return getattr(ctx_stack.top, 'jwt', {}) 
开发者ID:vimalloc,项目名称:flask-jwt-extended,代码行数:9,代码来源:utils.py

示例13: get_raw_jwt_header

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def get_raw_jwt_header():
    """
    In a protected endpoint, this will return the python dictionary which has
    the JWT headers values. If no
    JWT is currently present, an empty dict is returned instead.
    """
    return getattr(ctx_stack.top, 'jwt_header', {}) 
开发者ID:vimalloc,项目名称:flask-jwt-extended,代码行数:9,代码来源:utils.py

示例14: get_current_user

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def get_current_user():
    """
    In a protected endpoint, this will return the user object for the JWT that
    is accessing this endpoint. This is only present if the
    :meth:`~flask_jwt_extended.JWTManager.user_loader_callback_loader` is
    being used. If the user loader callback is not being used, this will
    return `None`.
    """
    return getattr(ctx_stack.top, 'jwt_user', None) 
开发者ID:vimalloc,项目名称:flask-jwt-extended,代码行数:11,代码来源:utils.py

示例15: get_request_attr

# 需要导入模块: from flask import _request_ctx_stack [as 别名]
# 或者: from flask._request_ctx_stack import top [as 别名]
def get_request_attr(name):
    """ Retrieve a request local attribute.

    Currently public attributes are:

    **fs_authn_via**
        will be set to the authentication mechanism (session, token, basic)
        that the current request was authenticated with.

    Returns None if attribute doesn't exist.

    .. versionadded:: 4.0.0
    """
    return getattr(_request_ctx_stack.top, name, None) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:16,代码来源:utils.py


注:本文中的flask._request_ctx_stack.top方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。