From 78feb6fb918213135236381eea192c38e0cb36c8 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Sun, 28 Oct 2007 14:32:25 +0000
Subject: [PATCH] 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
---
 lib/utils.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/utils.py b/lib/utils.py
index 907f27c00..d5d604b2f 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -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
-- 
GitLab