本文整理汇总了Python中pycket.session.SessionManager.set方法的典型用法代码示例。如果您正苦于以下问题:Python SessionManager.set方法的具体用法?Python SessionManager.set怎么用?Python SessionManager.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycket.session.SessionManager
的用法示例。
在下文中一共展示了SessionManager.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sets_session_id_on_cookies
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def sets_session_id_on_cookies(self):
test_case = self
class StubHandler(SessionMixin):
settings = {
'pycket': {
'engine': 'redis',
}
}
def get_secure_cookie(self, name):
test_case.assertEqual(name, 'PYCKET_ID')
self.cookie_set = True
return None
def set_secure_cookie(self, name, value, expires_days, expires):
test_case.assertEqual(name, 'PYCKET_ID')
test_case.assertIsInstance(value, str)
test_case.assertGreater(len(value), 0)
self.cookie_retrieved = True
handler = StubHandler()
session_manager = SessionManager(handler)
session_manager.set('some-object', 'Some object')
self.assertTrue(handler.cookie_retrieved)
self.assertTrue(handler.cookie_set)
示例2: post
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def post(self):
"""
"""
username = self.get_argument("username")
password = self.get_argument("password")
try:
connect_mongo.db.user.find_one({"username": username, "password": password})
if "username" == username & "password" == password:
session = SessionManager(self)
session.set('catId',username)
self.write("<script>alert('ورود موفقیت آمیز بود')</script>")
else:
self.render("Login.html")
# doc = connect_mongo.db.user.find_one({"username": username, "password": password})
# docc = doc["_id"]
# if docc > 0:
# session = SessionManager(self)
# session.set('loginid', docc)
# k = session.get('loginid')
# self.render("index.html")
except:
k = 1
self.render("Login.html", k=k)
示例3: retrieves_session_with_same_data_as_saved
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def retrieves_session_with_same_data_as_saved(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('some-object', {'foo': 'bar'})
self.assertEqual(manager.get('some-object')['foo'], 'bar')
示例4: retrieves_object_with_dict_key
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def retrieves_object_with_dict_key(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('foo', 'bar')
self.assertEqual(manager['foo'], 'bar')
示例5: gets_all_available_keys_from_session
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def gets_all_available_keys_from_session(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('foo', 'FOO')
manager.set('bar', 'BAR')
self.assertListEqual(sorted(manager.keys()), sorted(['foo', 'bar']))
示例6: keeps_previous_items_when_setting_new_ones
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def keeps_previous_items_when_setting_new_ones(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('some-object', {'foo': 'bar'})
manager.set('some-object2', {'foo2': 'bar2'})
self.assertEqual(manager.get('some-object')['foo'], 'bar')
self.assertEqual(manager.get('some-object2')['foo2'], 'bar2')
示例7: still_retrieves_object_if_not_passed_from_expiration
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def still_retrieves_object_if_not_passed_from_expiration(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('foo', 'bar')
time.sleep(1)
self.assertEqual(manager.get('foo'), 'bar')
示例8: deletes_item_using_command
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def deletes_item_using_command(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('some-object', {'foo': 'bar'})
del manager['some-object']
self.assertIsNone(manager.get('some-object'))
示例9: saves_session_object_on_redis_with_same_session_id_as_cookie
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def saves_session_object_on_redis_with_same_session_id_as_cookie(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('some-object', {'foo': 'bar'})
raw_session = self.client.get(handler.session_id)
session = pickle.loads(raw_session)
self.assertEqual(session['some-object']['foo'], 'bar')
示例10: cannot_retrieve_object_if_passed_from_expiration
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def cannot_retrieve_object_if_passed_from_expiration(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.driver.EXPIRE_SECONDS = 1
manager.set('foo', 'bar')
time.sleep(manager.driver.EXPIRE_SECONDS + 1)
self.assertIsNone(manager.get('foo'))
示例11: deletes_multiple_session_objects_at_once
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def deletes_multiple_session_objects_at_once(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('some-object', {'foo': 'bar'})
manager.set('some-object2', {'foo2': 'bar2'})
manager.delete('some-object', 'some-object2')
raw_session = self.client.get(handler.session_id)
session = pickle.loads(raw_session)
self.assertEqual(list(session.keys()), [])
示例12: deletes_objects_from_session
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def deletes_objects_from_session(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('some-object', {'foo': 'bar'})
manager.set('some-object2', {'foo2': 'bar2'})
manager.delete('some-object')
raw_session = self.client.get(handler.session_id)
session = pickle.loads(raw_session)
self.assertEqual(session.keys(), ['some-object2'])
示例13: get
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def get(self, *args, **kwargs):
# redis_instance.set(name='name', value='EHSAN')
# self.write(redis_instance.get(name='name'))
session = SessionManager(self)
# session.set('key', 'OMG')
session.set(name='key', value='OMG')
# session['key'] = 'OMG'
self.write(session.get(self, 'key'))
self.write(str(session.get('key')))
# self.write(str(session.keys()))
self.write(str(session.iterkeys()))
# self.write(session['key'])
self.write('done')
示例14: iterates_without_method_over_keys
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def iterates_without_method_over_keys(self):
handler = StubHandler()
manager = SessionManager(handler)
manager.set('foo', 'FOO')
manager.set('bar', 'BAR')
iterations = 0
for key in manager:
self.assertTrue(key in manager)
iterations += 1
self.assertEqual(iterations, 2)
示例15: uses_custom_sessions_database_if_provided
# 需要导入模块: from pycket.session import SessionManager [as 别名]
# 或者: from pycket.session.SessionManager import set [as 别名]
def uses_custom_sessions_database_if_provided(self):
handler = StubHandler()
handler.settings = {
'pycket': {
'engine': 'redis',
'storage': {
'db_sessions': 10,
'db_notifications': 11,
}
},
}
manager = SessionManager(handler)
manager.set('foo', 'bar')
self.assertEqual(manager.driver.client.connection_pool._available_connections[0].db, 10)