# HG changeset patch # User Adrien Di Mascio # Date 1234985023 -3600 # Node ID 3f08481e6e51dc0c75ca56f23ef083bd9e28d5c8 # Parent 51cb3d85c059a7356ce56e2362b4373390e662ff provide negation operator for selectors, unfortunately, it's not possible to user the python keyword 'not' diff -r 51cb3d85c059 -r 3f08481e6e51 vregistry.py --- 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 ########################################