[Zope-Checkins] CVS: Zope/lib/python/Products/Transience - Transience.py:1.28.6.2

Chris McDonough chrism@zope.com
Sat, 26 Oct 2002 11:41:34 -0400


Update of /cvs-repository/Zope/lib/python/Products/Transience
In directory cvs.zope.org:/tmp/cvs-serv3500

Modified Files:
      Tag: Zope-2_6-branch
	Transience.py 
Log Message:
Make TOC items and values sloppier.  These are utility methods used for custom introspection on the TOC.  Under concurrent use, they tended to cause a KeyError to be raised out of __getitem__ due to a synchronization problem.  Making them more tolerant of desynchronization between _items and _data makes them useful.


=== Zope/lib/python/Products/Transience/Transience.py 1.28.6.1 => 1.28.6.2 ===
--- Zope/lib/python/Products/Transience/Transience.py:1.28.6.1	Tue Oct 22 18:19:11 2002
+++ Zope/lib/python/Products/Transience/Transience.py	Sat Oct 26 11:41:34 2002
@@ -829,10 +829,46 @@
         return 1
 
     def values(self):
-        return map(lambda k, self=self: self[k], self.keys())
+        # sloppy and loving it!
+        # we used to use something like:
+        # [ self[x] for x in self.keys() ]
+        # but it was causing KeyErrors in getitem's "v = self._data[b][k]"
+        # due to some synchronization problem that I don't understand.
+        # since this is a utility method, I don't care too much. -cm
+        l = []
+        notfound = []
+        for k, t in self._index.items():
+            bucket = self._data.get(t, notfound)
+            if bucket is notfound:
+                continue
+            value = bucket.get(k, notfound)
+            if value is notfound:
+                continue
+            if hasattr(value, '__of__'):
+                value = value.__of__(self)
+            l.append(value)
+        return l
 
     def items(self):
-        return map(lambda k, self=self: (k, self[k]), self.keys())
+        # sloppy and loving it!
+        # we used to use something like:
+        # [ (x, self[x]) for x in self.keys() ]
+        # but it was causing KeyErrors in getitem's "v = self._data[b][k]"
+        # due to some synchronization problem that I don't understand.
+        # since this is a utility method, I don't care too much. -cm
+        l = []
+        notfound = []
+        for k, t in self._index.items():
+            bucket = self._data.get(t, notfound)
+            if bucket is notfound:
+                continue
+            value = bucket.get(k, notfound)
+            if value is notfound:
+                continue
+            if hasattr(value, '__of__'):
+                value = value.__of__(self)
+            l.append((k, value))
+        return l
 
     def true_items(self):
         l = []