def load(klass, request, response): """ Load the session cookies from the request, returning a new instance with the response. """ try: id = request.cookies['SID'][1:-SIG_LEN - 1] except KeyError: raise NoSIDError else: c = SignedCookie(SECRET_KEY + id) c.load(request.environ['HTTP_COOKIE']) try: user = User.get_by_key_name(c['user'].value) except KeyError: user = None session = klass(user, response) session.cookies = c return session
def load(klass, request, response): """ Load the session cookies from the request, returning a new instance with the response. """ try: id = request.cookies['SID'][1:-SIG_LEN-1] except KeyError: raise NoSIDError else: c = SignedCookie(SECRET_KEY + id) c.load(request.environ['HTTP_COOKIE']) try: user = User.get_by_key_name(c['user'].value) except KeyError: user = None session = klass(user, response) session.cookies = c return session