Commit 78feb6fb authored by Guido Trotter's avatar Guido Trotter
Browse files

Import two itertools recipes

The two function 'any' and 'all' are copied as-is from the python 2.4
documentation for the itertools module. They are useful (and are already
builtin function in python 2.5).

Reviewed-by: iustinp
parent 65a15336
......@@ -34,6 +34,7 @@ import tempfile
import shutil
import errno
import pwd
import itertools
from ganeti import logger
from ganeti import errors
......@@ -906,3 +907,17 @@ def WriteFile(file_name, fn=None, data=None,
finally:
os.close(fd)
RemoveFile(new_name)
def all(seq, pred=bool):
"Returns True if pred(x) is True for every element in the iterable"
for elem in itertools.ifilterfalse(pred, seq):
return False
return True
def any(seq, pred=bool):
"Returns True if pred(x) is True for at least one element in the iterable"
for elem in itertools.ifilter(pred, seq):
return True
return False
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