Revision 78feb6fb lib/utils.py

b/lib/utils.py
34 34
import shutil
35 35
import errno
36 36
import pwd
37
import itertools
37 38

  
38 39
from ganeti import logger
39 40
from ganeti import errors
......
906 907
  finally:
907 908
    os.close(fd)
908 909
    RemoveFile(new_name)
910

  
911

  
912
def all(seq, pred=bool):
913
  "Returns True if pred(x) is True for every element in the iterable"
914
  for elem in itertools.ifilterfalse(pred, seq):
915
    return False
916
  return True
917

  
918

  
919
def any(seq, pred=bool):
920
  "Returns True if pred(x) is True for at least one element in the iterable"
921
  for elem in itertools.ifilter(pred, seq):
922
    return True
923
  return False

Also available in: Unified diff