provide negation operator for selectors, unfortunately, it's not possible to user the python keyword 'not'
--- a/vregistry.py Wed Feb 18 19:45:28 2009 +0100
+++ b/vregistry.py Wed Feb 18 20:23:43 2009 +0100
@@ -592,6 +592,9 @@
return OrSelector(self, other)
def __ror__(self, other):
return OrSelector(other, self)
+
+ def __invert__(self):
+ return NotSelector(self)
# XXX (function | function) or (function & function) not managed yet
@@ -685,6 +688,17 @@
return partscore
return 0
+class NotSelector(Selector):
+ """negation selector"""
+ def __init__(self, selector):
+ self.selector = selector
+
+ def __call__(self, cls, *args, **kwargs):
+ score = self.selector(cls, *args, **kwargs)
+ return not score
+
+ def __str__(self):
+ return 'NOT(%s)' % super(NotSelector, self).__str__()
# advanced selector building functions ########################################