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


Python g.pop方法代碼示例

本文整理匯總了Python中flask.g.pop方法的典型用法代碼示例。如果您正苦於以下問題:Python g.pop方法的具體用法?Python g.pop怎麽用?Python g.pop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.g的用法示例。


在下文中一共展示了g.pop方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: logout_user

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import pop [as 別名]
def logout_user():
    """Logs out the current user.

    This will also clean up the remember me cookie if it exists.

    This sends an ``identity_changed`` signal to note that the current
    identity is now the `AnonymousIdentity`
    """

    for key in ("identity.name", "identity.auth_type", "fs_paa", "fs_gexp"):
        session.pop(key, None)

    # Clear csrf token between sessions.
    # Ideally this would be handled by Flask-WTF but...
    # We don't clear entire session since Flask-Login seems to like having it.
    csrf_field_name = find_csrf_field_name()
    if csrf_field_name:
        session.pop(csrf_field_name, None)
        # Flask-WTF 'caches' csrf_token - and only set the session if not already
        # in 'g'. Be sure to clear both. This affects at least /confirm
        g.pop(csrf_field_name, None)
    session["fs_cc"] = "clear"
    identity_changed.send(
        current_app._get_current_object(), identity=AnonymousIdentity()
    )
    _logout_user() 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:28,代碼來源:utils.py

示例2: find_redirect

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import pop [as 別名]
def find_redirect(key):
    """Returns the URL to redirect to after a user logs in successfully.

    :param key: The session or application configuration key to search for
    """
    rv = (
        get_url(session.pop(key.lower(), None))
        or get_url(current_app.config[key.upper()] or None)
        or "/"
    )
    return rv 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:13,代碼來源:utils.py

示例3: test_02_app_local_store

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import pop [as 別名]
def test_02_app_local_store(self):
        store1 = get_app_local_store()
        store1["hello"] = "world"
        g.test_flag = True

        # We get the same store even if we push another app context for the same app
        with self.app.app_context():
            store2 = get_app_local_store()
            self.assertEqual(store1, store2)
            self.assertEqual(store2["hello"], "world")
            self.assertNotIn("test_flag", g)
            g.test_flag = False

        self.assertEquals(g.test_flag, True)
        g.pop("test_flag")

        # We get a different store if we push a context for another app
        new_app = create_app("testing", "")
        with new_app.app_context():
            store3 = get_app_local_store()
            self.assertNotIn("hello", store3)
            self.assertNotEqual(store3, store1)
            store3["hello"] = "no!"
            store4 = get_app_local_store()
            store3["something"] = "else"
            self.assertEqual(store4["hello"], "no!")
            self.assertEqual(store4["something"], "else")

        self.assertEqual(store1, store2)
        self.assertEqual(store2["hello"], "world") 
開發者ID:privacyidea,項目名稱:privacyidea,代碼行數:32,代碼來源:test_lib_framework.py

示例4: close_topic_store

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import pop [as 別名]
def close_topic_store(e=None):
    topic_store = g.pop("topicstore", None)
    if topic_store is not None:
        topic_store.close() 
開發者ID:brettkromkamp,項目名稱:contextualise,代碼行數:6,代碼來源:topic_store.py

示例5: get_ca

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import pop [as 別名]
def get_ca() -> CertificateAuthority:
    if 'ca' not in g:
        try:
            ca = db.session.query(CertificateAuthority).filter_by(common_name='COMMANDMENT-CA').one()
        except sqlalchemy.orm.exc.NoResultFound:
            ca = CertificateAuthority.create()

        g.ca = ca

    return g.ca

#
# @current_app.teardown_appcontext
# def teardown_ca():
#     ca = g.pop('ca', None) 
開發者ID:cmdmnt,項目名稱:commandment,代碼行數:17,代碼來源:ca.py

示例6: close_db

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import pop [as 別名]
def close_db(e=None):
    """If this request connected to the database, close the
    connection.
    """
    db = g.pop('db', None)

    if db is not None:
        db.close() 
開發者ID:tonybaloney,項目名稱:azure-pipelines-python-examples,代碼行數:10,代碼來源:db.py


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