Commits

Mike Bayer committed 45562d7

CookieSession will add '_expires' value to data when an expire time is set, and uses
this when resending the cookie. Use session.expire() or session.delete() to remove.

Comments (0)

Files changed (1)

beaker/session.py

         """Saves the data for this session to persistent storage"""
         self._create_cookie()
     
+    def expire(self):
+        """Delete the 'expires' attribute on this Session, if any."""
+        
+        self.pop('_expires', None)
+        
     def _create_cookie(self):
         if '_creation_time' not in self:
             self['_creation_time'] = time.time()
         if '_id' not in self:
             self['_id'] = self._make_id()
         self['_accessed_time'] = time.time()
+        
+        
+        if self.cookie_expires is not True:
+            if self.cookie_expires is False:
+                expires = datetime.fromtimestamp( 0x7FFFFFFF )
+            elif isinstance(self.cookie_expires, timedelta):
+                expires = datetime.today() + self.cookie_expires
+            elif isinstance(self.cookie_expires, datetime):
+                expires = self.cookie_expires
+            else:
+                raise ValueError("Invalid argument for cookie_expires: %s"
+                                 % repr(self.cookie_expires))
+            self['_expires'] = expires
+        elif '_expires' in self:
+            expires = self['_expires']
+        else:
+            expires = None
+
         val = self._encrypt_data()
         if len(val) > 4064:
             raise BeakerException("Cookie value is too long to store")
             self.cookie[self.key]['secure'] = True
         
         self.cookie[self.key]['path'] = '/'
-        if self.cookie_expires is not True:
-            if self.cookie_expires is False:
-                expires = datetime.fromtimestamp( 0x7FFFFFFF )
-            elif isinstance(self.cookie_expires, timedelta):
-                expires = datetime.today() + self.cookie_expires
-            elif isinstance(self.cookie_expires, datetime):
-                expires = self.cookie_expires
-            else:
-                raise ValueError("Invalid argument for cookie_expires: %s"
-                                 % repr(self.cookie_expires))
+        
+        if expires:
             self.cookie[self.key]['expires'] = \
                 expires.strftime("%a, %d-%b-%Y %H:%M:%S GMT" )
         self.request['cookie_out'] = self.cookie[self.key].output(header='')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.