Commit 7f38c7b1 authored by Jeremy Hylton's avatar Jeremy Hylton

Python 2.1 compatibility.

parent 71c685b0
......@@ -214,7 +214,7 @@ class ClientStorage:
# _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 @@ class ClientStorage:
"""
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 @@ class ClientStorage:
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 @@ class ClientStorage:
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 @@ class ClientStorage:
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 @@ class InvalidationLogIterator:
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
......@@ -438,6 +438,7 @@ class ConnectionTests(CommonSetupTearDown):
self._storage = self.openClientStorage()
self._dostore()
# Test case for multiple storages participating in a single
# transaction. This is not really a connection test, but it needs
# about the same infrastructure (several storage servers).
......@@ -491,8 +492,12 @@ class ConnectionTests(CommonSetupTearDown):
get_transaction().commit()
# make sure the invalidation is received in the other client
c1._storage.sync()
self.assert_(r1._p_oid in c1._invalidated)
for i in range(10):
c1._storage.sync()
if c1._invalidated.has_key(r1._p_oid):
break
time.sleep(0.1)
self.assert_(c1._invalidated.has_key(r1._p_oid))
# force the invalidations to be applied...
c1.setLocalTransaction()
......
......@@ -13,7 +13,10 @@
##############################################################################
"""Database connection support
$Id: Connection.py,v 1.88 2003/04/08 15:55:44 jeremy Exp $"""
$Id: Connection.py,v 1.89 2003/04/22 18:04:37 jeremy Exp $"""
from __future__ import nested_scopes
from cPickleCache import PickleCache
from POSException import ConflictError, ReadConflictError, TransactionError
from ExtensionClass import Base
......
......@@ -13,8 +13,8 @@
##############################################################################
"""Database objects
$Id: DB.py,v 1.48 2003/04/08 15:55:44 jeremy Exp $"""
__version__='$Revision: 1.48 $'[11:-2]
$Id: DB.py,v 1.49 2003/04/22 18:04:37 jeremy Exp $"""
__version__='$Revision: 1.49 $'[11:-2]
import cPickle, cStringIO, sys, POSException, UndoLogCompatible
from Connection import Connection
......@@ -301,7 +301,7 @@ class DB(UndoLogCompatible.UndoLogCompatible):
version=connection._version
# Update modified in version cache
# XXX must make this work with list or dict to backport to 2.6
for oid in oids:
for oid in oids.keys():
h=hash(oid)%131
o=self._miv_cache.get(h, None)
if o is not None and o[0]==oid: del self._miv_cache[h]
......
......@@ -26,12 +26,12 @@ class P(Persistent):
class Independent(Persistent):
def _p_independent(self):
return True
return 1
class DecoyIndependent(Persistent):
def _p_independent(self):
return False
return 0
class ZODBTests(unittest.TestCase):
......@@ -193,7 +193,7 @@ class ZODBTests(unittest.TestCase):
self.obj = P()
self.readConflict()
def readConflict(self, shouldFail=True):
def readConflict(self, shouldFail=1):
# Two transactions run concurrently. Each reads some object,
# then one commits and the other tries to read an object
# modified by the first. This read should fail with a conflict
......@@ -237,10 +237,10 @@ class ZODBTests(unittest.TestCase):
root["real_data"] = real_data = PersistentDict()
root["index"] = index = PersistentDict()
real_data["a"] = PersistentDict({"indexed_value": False})
real_data["b"] = PersistentDict({"indexed_value": True})
index[True] = PersistentDict({"b": 1})
index[False] = PersistentDict({"a": 1})
real_data["a"] = PersistentDict({"indexed_value": 0})
real_data["b"] = PersistentDict({"indexed_value": 1})
index[1] = PersistentDict({"b": 1})
index[0] = PersistentDict({"a": 1})
get_transaction().commit()
# load some objects from one connection
......@@ -251,8 +251,8 @@ class ZODBTests(unittest.TestCase):
index2 = r2["index"]
real_data["b"]["indexed_value"] = False
del index[True]["b"]
index[False]["b"] = 1
del index[1]["b"]
index[0]["b"] = 1
cn2.getTransaction().commit()
del real_data2["a"]
......@@ -269,8 +269,8 @@ class ZODBTests(unittest.TestCase):
# index2 values not ready to commit
self.assert_(not index2._p_changed)
self.assert_(not index2[False]._p_changed)
self.assert_(not index2[True]._p_changed)
self.assert_(not index2[0]._p_changed)
self.assert_(not index2[1]._p_changed)
self.assertRaises(ConflictError, get_transaction().commit)
get_transaction().abort()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment