Example #1
0
    def __call__(self, environ, start_response):
        # initialize a session for the current user
        _tls.current_session = Session(
            lifetime=self.lifetime,
            no_datastore=self.no_datastore,
            cookie_only_threshold=self.cookie_only_thresh,
            cookie_key=self.cookie_key)

        # create a hook for us to insert a cookie into the response headers
        def my_start_response(status, headers, exc_info=None):
            try:
                _tls.current_session.save(
                )  # store the session if it was changed
            except ValueError:  # 1Mb memcache limit
                _tls.current_session.clear()

            for ch in _tls.current_session.make_cookie_headers():
                headers.append(('Set-Cookie', ch))

            return start_response(status, headers, exc_info)

        # let the app do its thing
        return self.app(environ, my_start_response)
Example #2
0
 def get(self):
     s = Session(sid=self.request.get('sid'), cookie_key='dontcare')
     s.ensure_data_loaded()
     self.response.out.write(b64encode(pickle.dumps(s.data)))