summaryrefslogtreecommitdiff
path: root/compat.py
diff options
context:
space:
mode:
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2006-06-20 10:58:19 +0200
committerAdrien Di Mascio <Adrien.DiMascio@logilab.fr>2006-06-20 10:58:19 +0200
commitaafd84cd45312cd197afcb01ac4d605d52d1209f (patch)
tree346567fd1fbc51cdef8f7525f41fdd15d96d4cea /compat.py
parent9bf7768129e98d76aa87552844fe56a49a291bcf (diff)
downloadlogilab-common-aafd84cd45312cd197afcb01ac4d605d52d1209f.tar.gz
adds any/all builtins
Diffstat (limited to 'compat.py')
-rw-r--r--compat.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/compat.py b/compat.py
index 6100070..4a34e38 100644
--- a/compat.py
+++ b/compat.py
@@ -188,3 +188,28 @@ except NameError:
l2 = list(l)
l2.reverse()
return l2
+
+# Python2.5 builtins
+try:
+ any = any
+ all = all
+except NameError:
+ def any(iterable):
+ """any(iterable) -> bool
+
+ Return True if bool(x) is True for any x in the iterable.
+ """
+ for elt in iterable:
+ if bool(elt):
+ return True
+ return False
+
+ def all(iterable):
+ """all(iterable) -> bool
+
+ Return True if bool(x) is True for all values x in the iterable.
+ """
+ for elt in iterable:
+ if not bool(elt):
+ return False
+ return True