[Zope-CVS] CVS: Products/Transience - Transience.py:1.13

Matthew T. Kromer matt@zope.com
Thu, 8 Nov 2001 16:02:44 -0500


Update of /cvs-repository/Products/Transience
In directory cvs.zope.org:/tmp/cvs-serv22403

Modified Files:
	Transience.py 
Log Message:
Make sure new will return new Transient if the old one is invalid


=== Products/Transience/Transience.py 1.12 => 1.13 ===
             raise TypeError, (key, "key is not a string type")
         if self.has_key(key):
-            raise KeyError, key         # Not allowed to dup keys
+            if self[key].isValid():
+                raise KeyError, key         # Not allowed to dup keys
+             del self[key]      
         
         item = TransientObject(key)
         self[key] = item
@@ -460,7 +462,7 @@
             index[k] = current
         # change the value
         current[k] = v
-        v.setLastAccessed()
+        self._setLastAccessed(v)
         
     def __getitem__(self, k):
         current = self._getCurrentBucket()
@@ -473,11 +475,17 @@
             # we accessed the object, so it should become current.
             index[k] = current # change the index to the current bucket.
             current[k] = v # add the value to the current bucket.
-            v.setLastAccessed()
+            self._setLastAccessed(v)
             del b[k] # delete the item from the old bucket.
         return v
 
-    security.declareProtected(ACCESS_TRANSIENTS_PERM, 'get')
+    def _setLastAccessed(self, transientObject):
+        # A safety valve; dont try to set the last accessed time if the
+        # object we were given doesnt support it
+        sla = getattr(transientObject, 'setLastAccessed', None)
+        if sla is not None: sla()
+
+    security.declareProtected(ACCESS_TRANSIENTS_PERM, 'set')
     def set(self, k, v):
         """ """
         if type(k) is not type(''):