added implicit sync on accessing a SyncedList.

This commit is contained in:
Adi Sieker
2011-04-10 23:54:23 +02:00
parent bd3c06d2a7
commit fe7c5af03c
2 changed files with 14 additions and 5 deletions
+12 -3
View File
@@ -24,15 +24,22 @@ class SyncedList(object):
def __init__(self):
self.data = []
#if hasattr(self, 'sync'):
# self.sync()
self._synced = False
def __repr__(self):
return str(self.data)
def _sync(self):
"""private method that makes sure the list is synced
when first acessed."""
#we sync on first access.
if self._synced == False and hasattr(self, 'sync') == True:
self.sync()
self._synced = True
def __getitem__(self, key):
#make sure we have been synced
self._sync()
if isinstance(key, int):
key = unicode(key)
@@ -67,6 +74,8 @@ class SyncedList(object):
def __contains__(self, key):
#make sure we have been synced
self._sync()
if isinstance(key, int):
key = unicode(key)
+2 -2
View File
@@ -27,7 +27,7 @@ CONVORE_PASS = os.environ.get('CONVORE_PASS', 'requeststest')
class ConvoreAPI(unittest.TestCase):
"""Requests test cases."""
def setUp(self):
self.convore = convore.Convore(CONVORE_NAME, CONVORE_PASS)
@@ -44,7 +44,7 @@ class ConvoreAPI(unittest.TestCase):
class ConvoreGroups(unittest.TestCase):
def setUp(self):
self.convore = convore.Convore(CONVORE_NAME, CONVORE_PASS)
def test_works(self):
self.convore.groups