mirror of
https://github.com/kennethreitz-archive/python-convore.git
synced 2026-06-05 23:40:18 +00:00
added implicit sync on accessing a SyncedList.
This commit is contained in:
+12
-3
@@ -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
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user