Commits

Ben Bangert  committed a3e52c8

* Adding 'id' to cookie-based sessions for better compatibility.

  • Participants
  • Parent commits e08fcc2

Comments (0)

Files changed (3)

 ================
 
 0.9.3 (2/28/2008)
+* Adding 'id' to cookie-based sessions for better compatibility.
 * Fixed error with exception still raised for PyCrypto missing.
 * WARNING: Session middleware no longer catches Paste HTTP Exceptions, apps
   are now expected to capture and handle Paste HTTP Exceptions themselves.

File beaker/session.py

             self.cookie = SignedCookie(validate_key, input=None)
         
         self.dict = {}
+        self.dict['_id'] = self._make_id()
         self.is_new = True
         
         # If we have a cookie, load it
             self._create_cookie()
     
     created = property(lambda self: self.dict['_creation_time'])
+    id = property(lambda self: self.dict['_id'])
     
     def _encrypt_data(self):
         """Cerealize, encipher, and base64 the session dict"""
             data = base64.b64decode(self.cookie[self.key].value)
             return cPickle.loads(data)
     
+    def _make_id(self):
+        return md5.new(md5.new(
+            "%f%s%f%d" % (time.time(), id({}), random.random(), os.getpid())
+            ).hexdigest()
+        ).hexdigest()
+    
     def save(self):
         "saves the data for this session to persistent storage"
         self._create_cookie()
     def _create_cookie(self):
         if '_creation_time' not in self.dict:
             self.dict['_creation_time'] = time.time()
+        if '_id' not in self.dict:
+            self.dict['_id'] = self._make_id()
         self.dict['_accessed_time'] = time.time()
         val = self._encrypt_data()
         if len(val) > 4064:
                 expires.strftime("%a, %d-%b-%Y %H:%M:%S GMT" )
         self.request['cookie_out'] = self.cookie[self.key].output(header='')
         self.request['set_cookie'] = True
+    
+    def delete(self):
+        # Clear out the cookie contents, best we can do
+        self.dict = {}
+        self._create_cookie()
+    
+    # Alias invalidate to delete
+    invalidate = delete
 
 
 class SessionObject(object):