def getSession(self, clear_cookie=False):
sid = None
if ('Cookie' in self.request_handler.headers):
cookie = Cookie.SimpleCookie()
cookie.load(self.request_handler.headers.getheader('Cookie'))
if ('sid' in cookie and cookie['sid']):
sid = cookie['sid'].value
if not sid or clear_cookie:
cookie = Cookie.SimpleCookie()
sid = str(sha.new(repr(time.time())).hexdigest())
cookie['sid'] = sid
cookie['sid']['path'] = '/'
expires = (time.time() + 14 * 24 * 3600)
cookie['sid']['expires'] = time.strftime("%a, %d-%b-%Y %T GMT", time.gmtime(expires))
cookie_output = cookie.output().split(': ')
RedisConnection.hset('session_' + str(sid), 'exists', '1')
self.headers[cookie_output[0]] = cookie_output[1]
return sid
评论列表
文章目录