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


Python SecureCookie.serialize方法代码示例

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


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

示例1: test_basic_support

# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def test_basic_support():
    c = SecureCookie(secret_key=b'foo')
    assert c.new
    assert not c.modified
    assert not c.should_save
    c['x'] = 42
    assert c.modified
    assert c.should_save
    s = c.serialize()

    c2 = SecureCookie.unserialize(s, b'foo')
    assert c is not c2
    assert not c2.new
    assert not c2.modified
    assert not c2.should_save
    assert c2 == c

    c3 = SecureCookie.unserialize(s, b'wrong foo')
    assert not c3.modified
    assert not c3.new
    assert c3 == {}

    c4 = SecureCookie({'x': 42}, 'foo')
    c4_serialized = c4.serialize()
    assert SecureCookie.unserialize(c4_serialized, 'foo') == c4
开发者ID:brunoais,项目名称:werkzeug,代码行数:27,代码来源:test_securecookie.py

示例2: fake_login

# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def fake_login(request):
    if request.method == 'GET':
        return Response("FAKE LOGIN", mimetype="text/html")
    elif request.method == 'POST':
        response = Response("LOGGED IN", mimetype="text/html")
        cookie = SecureCookie({"logged_in": True}, SECRET_KEY)
        response.set_cookie('session_data', cookie.serialize())
        return response
开发者ID:bhuztez,项目名称:werkzeug-openid-provider,代码行数:10,代码来源:tests.py

示例3: set_gaema_user

# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
def set_gaema_user(service, user):
  gaema_user_key = GAEMA_USER_KEY_FORMAT % service
  if hasattr(settings, "GAEMA_STORAGE") and settings.GAEMA_STORAGE == "cookie":
    secure_cookie = SecureCookie(user, secret_key=settings.SECRET_KEY)
    user_data = secure_cookie.serialize()
    set_cookie(gaema_user_key, user_data)
  else:
    from kay.sessions import renew_session
    renew_session(local.request)
    local.request.session[gaema_user_key] = user
    local.request.session.modified = True
开发者ID:IanLewis,项目名称:kay,代码行数:13,代码来源:utils.py

示例4: post_process

# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
 def post_process(self, environ, headers):
     user = User.get_current()
     if not user:
         cookies = http.parse_cookie(environ)
         if self.name in cookies:
             raw = http.dump_cookie(self.name, '', expires=1)
             headers.append((utils.to_native('Set-Cookie'), raw))
         return
     cookie = SecureCookie({
         'uid': user.id,
         'session_token': user.get_session_token(),
     }, self.secret)
     raw = http.dump_cookie(self.name, cookie.serialize(),
                            expires=self.expires, max_age=self.max_age)
     headers.append((utils.to_native('Set-Cookie'), raw))
开发者ID:leancloud,项目名称:python-sdk,代码行数:17,代码来源:cookie_session.py

示例5: test_basic_support

# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
    def test_basic_support(self):
        c = SecureCookie(secret_key='foo')
        assert c.new
        assert not c.modified
        assert not c.should_save
        c['x'] = 42
        assert c.modified
        assert c.should_save
        s = c.serialize()

        c2 = SecureCookie.unserialize(s, 'foo')
        assert c is not c2
        assert not c2.new
        assert not c2.modified
        assert not c2.should_save
        assert c2 == c

        c3 = SecureCookie.unserialize(s, 'wrong foo')
        assert not c3.modified
        assert not c3.new
        assert c3 == {}
开发者ID:AnIrishDuck,项目名称:werkzeug,代码行数:23,代码来源:securecookie.py

示例6: test_basic_support

# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
    def test_basic_support(self):
        c = SecureCookie(secret_key=b'foo')
        assert c.new
        assert not c.modified
        assert not c.should_save
        c['x'] = 42
        assert c.modified
        assert c.should_save
        s = c.serialize()

        c2 = SecureCookie.unserialize(s, b'foo')
        assert c is not c2
        assert not c2.new
        assert not c2.modified
        assert not c2.should_save
        self.assert_equal(c2, c)

        c3 = SecureCookie.unserialize(s, b'wrong foo')
        assert not c3.modified
        assert not c3.new
        self.assert_equal(c3, {})
开发者ID:211sandiego,项目名称:calllog211,代码行数:23,代码来源:securecookie.py

示例7: test_basic_support

# 需要导入模块: from werkzeug.contrib.securecookie import SecureCookie [as 别名]
# 或者: from werkzeug.contrib.securecookie.SecureCookie import serialize [as 别名]
    def test_basic_support(self):
        c = SecureCookie(secret_key="foo")
        assert c.new
        print c.modified, c.should_save
        assert not c.modified
        assert not c.should_save
        c["x"] = 42
        assert c.modified
        assert c.should_save
        s = c.serialize()

        c2 = SecureCookie.unserialize(s, "foo")
        assert c is not c2
        assert not c2.new
        assert not c2.modified
        assert not c2.should_save
        assert c2 == c

        c3 = SecureCookie.unserialize(s, "wrong foo")
        assert not c3.modified
        assert not c3.new
        assert c3 == {}
开发者ID:FakeSherlock,项目名称:Report,代码行数:24,代码来源:securecookie.py


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