[PATCH 1 of 3] util: add any() and all() functions for Python 2.4 compatibility

Steve Losh steve at stevelosh.com
Fri Feb 12 19:11:15 CST 2010


# HG changeset patch
# User Steve Losh <steve at stevelosh.com>
# Date 1266022749 18000
# Node ID 60564b40a8f6989fdb1b2997e4ce5334ffc4544c
# Parent  1c50a954a5244a8da8d6d2311dd12d6a5f6df357
util: add any() and all() functions for Python 2.4 compatibility

This patch adds these two very useful functions to the mercurial.util module,
because they are not present in Python 2.4.

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1335,10 +1335,22 @@
         pid = spawndetached(args)
         while not condfn():
             if ((pid in terminated or not testpid(pid))
                 and not condfn()):
                 return -1
             time.sleep(0.1)
         return pid
     finally:
         if prevhandler is not None:
             signal.signal(signal.SIGCHLD, prevhandler)
+
+def any(iterable):
+    for i in iterable:
+        if i:
+            return True
+    return False
+
+def all(iterable):
+    for i in iterable:
+        if not i:
+            return False
+    return True


More information about the Mercurial-devel mailing list