[Zodb-checkins] CVS: ZODB3/ZEO - ClientStorage.py:1.93

Jeremy Hylton jeremy at zope.com
Tue Apr 22 15:00:47 EDT 2003


Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv5952/ZEO

Modified Files:
	ClientStorage.py 
Log Message:
Python 2.1 compatibility.


=== ZODB3/ZEO/ClientStorage.py 1.92 => 1.93 ===
--- ZODB3/ZEO/ClientStorage.py:1.92	Wed Apr  9 18:43:52 2003
+++ ZODB3/ZEO/ClientStorage.py	Tue Apr 22 14:00:16 2003
@@ -214,7 +214,7 @@
         # _is_read_only stores the constructor argument
         self._is_read_only = read_only
         # _conn_is_read_only stores the status of the current connection
-        self._conn_is_read_only = False
+        self._conn_is_read_only = 0
         self._storage = storage
         self._read_only_fallback = read_only_fallback
         # _server_addr is used by sortKey()
@@ -367,7 +367,7 @@
         """
         log2(INFO, "Testing connection %r" % conn)
         # XXX Check the protocol version here?
-        self._conn_is_read_only = False
+        self._conn_is_read_only = 0
         stub = self.StorageServerStubClass(conn)
         try:
             stub.register(str(self._storage), self._is_read_only)
@@ -377,7 +377,7 @@
                 raise
             log2(INFO, "Got ReadOnlyError; trying again with read_only=1")
             stub.register(str(self._storage), read_only=1)
-            self._conn_is_read_only = True
+            self._conn_is_read_only = 1
             return 0
 
     def notifyConnected(self, conn):
@@ -559,7 +559,7 @@
     def isReadOnly(self):
         """Storage API: return whether we are in read-only mode."""
         if self._is_read_only:
-            return True
+            return 1
         else:
             # If the client is configured for a read-write connection
             # but has a read-only fallback connection, _conn_is_read_only
@@ -961,12 +961,18 @@
     end = endVerify
     Invalidate = invalidateTrans
 
+try:
+    StopIteration
+except NameError:
+    class StopIteration(Exception):
+        pass
+
 class InvalidationLogIterator:
     """Helper class for reading invalidations in endVerify."""
-    # XXX will require extra work to backport to Python 2.1
 
     def __init__(self, fileobj):
         self._unpickler = cPickle.Unpickler(fileobj)
+        self.getitem_i = 0
 
     def __iter__(self):
         return self
@@ -976,3 +982,15 @@
         if oid is None:
             raise StopIteration
         return oid, version
+
+    # The __getitem__() method is needed to support iteration
+    # in Python 2.1.
+
+    def __getitem__(self, i):
+        assert i == self.getitem_i
+        try:
+            obj = self.next()
+        except StopIteration:
+            raise IndexError, i
+        self.getitem_i += 1
+        return obj




More information about the Zodb-checkins mailing list