page_base.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Tuckshop 作者: MatthewJohn 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号