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


Python Flak.secret_key方法代码示例

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


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

示例1: test_redirect_keep_session

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_redirect_keep_session():
    app = Flak(__name__)
    app.secret_key = 'testing'

    @app.route('/', methods=['GET', 'POST'])
    def index(cx):
        if cx.request.method == 'POST':
            return flak.redirect('/getsession')
        cx.session['data'] = 'foo'
        return 'index'

    @app.route('/getsession')
    def get_session(cx):
        return cx.session.get('data', '<missing>')

    with app.test_client() as c:
        rv = c.get('/getsession')
        assert rv.data == b'<missing>'

        rv = c.get('/')
        assert rv.data == b'index'
        rv = c.post('/', data={}, follow_redirects=True)
        assert rv.data == b'foo'
        rv = c.get('/getsession')
        assert rv.data == b'foo'
开发者ID:avdd,项目名称:flak,代码行数:27,代码来源:test_testing.py

示例2: test_session_special_types

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_session_special_types():
    app = Flak(__name__)
    app.secret_key = 'development-key'
    now = datetime.utcnow().replace(microsecond=0)
    the_uuid = uuid.uuid4()

    @app.after_request
    def modify_session(cx, response):
        cx.session['u'] = the_uuid
        cx.session['dt'] = now
        cx.session['b'] = b'\xff'
        cx.session['t'] = (1, 2, 3)
        return response

    @app.route('/')
    def dump_session_contents(cx):
        return pickle.dumps(dict(cx.session))

    c = app.test_client()
    c.get('/')
    rv = pickle.loads(c.get('/').data)
    assert rv['dt'] == now
    assert rv['u'] == the_uuid
    assert rv['b'] == b'\xff'
    assert type(rv['b']) == bytes
    assert rv['t'] == (1, 2, 3)
开发者ID:avdd,项目名称:flak,代码行数:28,代码来源:test_basic.py

示例3: test_session_expiration

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_session_expiration():
    permanent = True
    app = Flak(__name__)
    app.secret_key = 'testkey'

    @app.route('/')
    def index(cx):
        cx.session['test'] = 42
        cx.session.permanent = permanent
        return ''

    @app.route('/test')
    def test(cx):
        return text_type(cx.session.permanent)

    client = app.test_client()
    rv = client.get('/')
    assert 'set-cookie' in rv.headers
    match = re.search(r'\bexpires=([^;]+)(?i)', rv.headers['set-cookie'])
    expires = parse_date(match.group())
    expected = datetime.utcnow() + app.permanent_session_lifetime
    assert expires.year == expected.year
    assert expires.month == expected.month
    assert expires.day == expected.day

    rv = client.get('/test')
    assert rv.data == b'True'

    permanent = False
    rv = app.test_client().get('/')
    assert 'set-cookie' in rv.headers
    match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
    assert match is None
开发者ID:avdd,项目名称:flak,代码行数:35,代码来源:test_basic.py

示例4: test_session_transactions_keep_context

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_session_transactions_keep_context():
    app = Flak(__name__)
    app.secret_key = 'testing'

    with app.test_client() as c:
        rv = c.get('/')
        cx = c.captured_context
        req = cx.request
        assert req is not None
        with c.session():
            assert req is cx.request
开发者ID:avdd,项目名称:flak,代码行数:13,代码来源:test_testing.py

示例5: test_session_stored_last

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_session_stored_last():
    app = Flak(__name__)
    app.secret_key = 'development-key'

    @app.after_request
    def modify_session(cx, response):
        cx.session['foo'] = 42
        return response

    @app.route('/')
    def dump_session_contents(cx):
        return repr(cx.session.get('foo'))

    c = app.test_client()
    assert c.get('/').data == b'None'
    assert c.get('/').data == b'42'
开发者ID:avdd,项目名称:flak,代码行数:18,代码来源:test_basic.py

示例6: test_session

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_session():
    app = Flak(__name__)
    app.secret_key = 'testkey'

    @app.route('/set', methods=['POST'])
    def set(cx):
        cx.session['value'] = cx.request.form['value']
        return 'value set'

    @app.route('/get')
    def get(cx):
        return cx.session['value']

    c = app.test_client()
    assert c.post('/set', data={'value': '42'}).data == b'value set'
    assert c.get('/get').data == b'42'
开发者ID:avdd,项目名称:flak,代码行数:18,代码来源:test_basic.py

示例7: test_session_transactions

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_session_transactions():
    app = Flak(__name__)
    app.secret_key = 'testing'

    @app.route('/')
    def index(cx):
        return text_type(cx.session['foo'])

    with app.test_client() as c:
        with c.session() as sess:
            assert len(sess) == 0
            sess['foo'] = [42]
            assert len(sess) == 1
        rv = c.get('/')
        assert rv.data == b'[42]'
        with c.session() as sess:
            assert len(sess) == 1
            assert sess['foo'] == [42]
开发者ID:avdd,项目名称:flak,代码行数:20,代码来源:test_testing.py

示例8: test_session_cookie_setting

# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import secret_key [as 别名]
def test_session_cookie_setting():
    app = Flak(__name__)
    app.secret_key = 'dev key'
    is_permanent = True

    @app.route('/bump')
    def bump(cx):
        rv = cx.session['foo'] = cx.session.get('foo', 0) + 1
        cx.session.permanent = is_permanent
        return str(rv)

    @app.route('/read')
    def read(cx):
        return str(cx.session.get('foo', 0))

    def run_test(expect_header):
        with app.test_client() as c:
            assert c.get('/bump').data == b'1'
            assert c.get('/bump').data == b'2'
            assert c.get('/bump').data == b'3'

            rv = c.get('/read')
            set_cookie = rv.headers.get('set-cookie')
            assert (set_cookie is not None) == expect_header
            assert rv.data == b'3'

    is_permanent = True
    app.config['SESSION_REFRESH_EACH_REQUEST'] = True
    run_test(expect_header=True)

    is_permanent = True
    app.config['SESSION_REFRESH_EACH_REQUEST'] = False
    run_test(expect_header=False)

    is_permanent = False
    app.config['SESSION_REFRESH_EACH_REQUEST'] = True
    run_test(expect_header=False)

    is_permanent = False
    app.config['SESSION_REFRESH_EACH_REQUEST'] = False
    run_test(expect_header=False)
开发者ID:avdd,项目名称:flak,代码行数:43,代码来源:test_basic.py


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