Add gather function and robustify class methods' failure handling.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
cl349@firebug.cl.cam.ac.uk committed 2005-09-14 18:24:25 +00:00
1 parent 6d496fed5e
commit 967d7a84e5
1 file changed
+52
@@ -106,6 +106,23 @@ class xstransact:
ret.extend(self._list(key))
return ret
def gather(self, *args):
ret = []
for tup in args:
if len(tup) == 2:
(key, fn) = tup
defval = None
else:
(key, fn, defval) = tup
try:
val = fn(self.read(key))
except TypeError:
val = defval
ret.append(val)
if len(ret) == 1:
return ret[0]
return ret
def Read(cls, path, *args):
while True:
@@ -115,10 +132,14 @@ class xstransact:
t.commit()
return v
except RuntimeError, ex:
t.abort()
if ex.args[0] == errno.ETIMEDOUT:
pass
else:
raise
except:
t.abort()
raise
Read = classmethod(Read)
@@ -130,10 +151,14 @@ class xstransact:
t.commit()
return
except RuntimeError, ex:
t.abort()
if ex.args[0] == errno.ETIMEDOUT:
pass
else:
raise
except:
t.abort()
raise
Write = classmethod(Write)
@@ -145,10 +170,14 @@ class xstransact:
t.commit()
return
except RuntimeError, ex:
t.abort()
if ex.args[0] == errno.ETIMEDOUT:
pass
else:
raise
except:
t.abort()
raise
Remove = classmethod(Remove)
@@ -160,9 +189,32 @@ class xstransact:
t.commit()
return v
except RuntimeError, ex:
t.abort()
if ex.args[0] == errno.ETIMEDOUT:
pass
else:
raise
except:
t.abort()
raise
List = classmethod(List)
def Gather(cls, path, *args):
while True:
try:
t = cls(path)
v = t.gather(*args)
t.commit()
return v
except RuntimeError, ex:
t.abort()
if ex.args[0] == errno.ETIMEDOUT:
pass
else:
raise
except:
t.abort()
raise
Gather = classmethod(Gather)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.