From cd14c16c2c6a91af6a9d43aaffeefca7d72f5eee Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 21 Sep 2010 09:58:53 +0200 Subject: [PATCH] Add two more _T-type tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are useful for more in-depth checking of some kinds of arguments. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: RenΓ© Nussbaumer <rn@google.com> --- lib/cmdlib.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 481b1255a..0b3ab5453 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -154,6 +154,13 @@ def _TDict(val): return isinstance(val, dict) +def _TIsLength(size): + """Check is the given container is of the given size. + + """ + return lambda container: len(container) == size + + # Combinator types def _TAnd(*args): """Combine multiple functions using an AND operation. @@ -173,6 +180,13 @@ def _TOr(*args): return fn +def _TMap(fn, test): + """Checks that a modified version of the argument passes the given test. + + """ + return lambda val: test(fn(val)) + + # Type aliases #: a non-empty string -- GitLab