Permalink
Browse files

Add a negation operator.

  • Loading branch information...
1 parent d22581c commit 6e857bb2fc48294eb85e4508e2bf85c907ceece2 @ralphbean ralphbean committed Mar 4, 2014
Showing with 9 additions and 2 deletions.
  1. +9 −2 fedbadges/rules.py
  2. 0 tests/{test_criteria.py → test_criteria_datanommer.py}
View
@@ -42,7 +42,7 @@
operators = set([
"all",
"any",
- #"not",
+ "not",
])
lambdas = set([
"lambda",
@@ -51,6 +51,7 @@
operator_lookup = {
"any": any,
"all": all,
+ "not": lambda x: all([not item for item in x])
}
fedmsg_config = fedmsg.config.load_config()
@@ -243,7 +244,13 @@ def __init__(self, *args, **kwargs):
self.attribute = self._d.keys()[0]
self.expected_value = self._d[self.attribute]
- # Check if we should we recursively nest Trigger/Criteria?
+ ### Check if we should we recursively nest Trigger/Criteria?
+
+ # First, trick negation into thinking it is not a unary operator.
+ if self.attribute == 'not':
+ self.expected_value = [self.expected_value]
+
+ # Then, treat everything as if it accepts an arbitrary # of args.
if self.attribute in operators:
if not isinstance(self.expected_value, list):
raise TypeError("Operators only accept lists, not %r" %
File renamed without changes.

0 comments on commit 6e857bb

Please sign in to comment.