[Zodb-checkins] CVS: ZODB3/ZEO - ClientStorage.py:1.114
TransactionBuffer.py:1.9
Jeremy Hylton
jeremy at zope.com
Fri Dec 26 16:06:15 EST 2003
Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv22092/ZEO
Modified Files:
ClientStorage.py TransactionBuffer.py
Log Message:
Change TransactionBuffer to use a real iterator.
This eliminates a bunch of checks that weren't exercised by the test
suite. Not sure if they were superstition or not, but I'm willing to
risk it.
=== ZODB3/ZEO/ClientStorage.py 1.113 => 1.114 ===
--- ZODB3/ZEO/ClientStorage.py:1.113 Wed Dec 24 11:02:03 2003
+++ ZODB3/ZEO/ClientStorage.py Fri Dec 26 16:05:43 2003
@@ -985,22 +985,7 @@
if self._cache is None:
return
- try:
- self._tbuf.begin_iterate()
- except ValueError, msg:
- raise ClientStorageError, (
- "Unexpected error reading temporary file in "
- "client storage: %s" % msg)
- while 1:
- try:
- t = self._tbuf.next()
- except ValueError, msg:
- raise ClientStorageError, (
- "Unexpected error reading temporary file in "
- "client storage: %s" % msg)
- if t is None:
- break
- oid, version, data = t
+ for oid, version, data in self._tbuf:
self._cache.invalidate(oid, version, tid)
# If data is None, we just invalidate.
if data is not None:
=== ZODB3/ZEO/TransactionBuffer.py 1.8 => 1.9 ===
--- ZODB3/ZEO/TransactionBuffer.py:1.8 Thu Oct 3 12:57:55 2002
+++ ZODB3/ZEO/TransactionBuffer.py Fri Dec 26 16:05:43 2003
@@ -116,41 +116,33 @@
finally:
self.lock.release()
- # unchecked constraints:
- # 1. can't call store() after begin_iterate()
- # 2. must call clear() after iteration finishes
-
- def begin_iterate(self):
- """Move the file pointer in advance of iteration"""
+ def __iter__(self):
self.lock.acquire()
try:
if self.closed:
return
self.file.flush()
self.file.seek(0)
- self.unpickler = cPickle.Unpickler(self.file)
+ return TBIterator(self.file, self.count)
finally:
self.lock.release()
- def next(self):
- self.lock.acquire()
- try:
- return self._next()
- finally:
- self.lock.release()
+class TBIterator(object):
- def _next(self):
+ def __init__(self, f, count):
+ self.file = f
+ self.count = count
+ self.unpickler = cPickle.Unpickler(f)
+
+ def __iter__(self):
+ return self
+
+ def next(self):
"""Return next tuple of data or None if EOF"""
- if self.closed:
- return None
if self.count == 0:
- del self.unpickler
- return None
+ self.file.seek(0)
+ self.size = 0
+ raise StopIteration
oid_ver_data = self.unpickler.load()
self.count -= 1
return oid_ver_data
-
- def get_size(self):
- """Return size of data stored in buffer (just a hint)."""
-
- return self.size
More information about the Zodb-checkins
mailing list