1
2
3
4
5 """
6 Composite criteria allow to use several criteria together, with and/or composition
7 """
8
9 import sys
10
11 if sys.version < '2.5':
13 for element in iterable:
14 if not element:
15 return False
16 return True
17
19 for element in iterable:
20 if element:
21 return True
22 return False
23
25 """
26 Compose several criteria with an or rule
27 """
29 """
30 Collects the different criteria
31 """
32 self.criteria = kwargs.values() + list(args)
33
35 """
36 Evaluates each criterion (no lazy evaluation) and returns True if one of them is True
37 """
38 r = [criterion(state, **kwargs) for criterion in self.criteria]
39 return any(r)
40
42 """
43 Compose several criteria with an and rule
44 """
46 """
47 Collects the different criteria
48 """
49 self.criteria = kwargs.values() + list(args)
50
52 """
53 Evaluates each criterion (no lazy evaluation) and returns True if one of them is True
54 """
55 r = [criterion(state, **kwargs) for criterion in self.criteria]
56 return all(r)
57