當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。