equal
deleted
inserted
replaced
590 |
590 |
591 def __or__(self, other): |
591 def __or__(self, other): |
592 return OrSelector(self, other) |
592 return OrSelector(self, other) |
593 def __ror__(self, other): |
593 def __ror__(self, other): |
594 return OrSelector(other, self) |
594 return OrSelector(other, self) |
|
595 |
|
596 def __invert__(self): |
|
597 return NotSelector(self) |
595 |
598 |
596 # XXX (function | function) or (function & function) not managed yet |
599 # XXX (function | function) or (function & function) not managed yet |
597 |
600 |
598 def __call__(self, cls, *args, **kwargs): |
601 def __call__(self, cls, *args, **kwargs): |
599 return NotImplementedError("selector %s must implement its logic " |
602 return NotImplementedError("selector %s must implement its logic " |
683 partscore = selector(cls, *args, **kwargs) |
686 partscore = selector(cls, *args, **kwargs) |
684 if partscore: |
687 if partscore: |
685 return partscore |
688 return partscore |
686 return 0 |
689 return 0 |
687 |
690 |
|
691 class NotSelector(Selector): |
|
692 """negation selector""" |
|
693 def __init__(self, selector): |
|
694 self.selector = selector |
|
695 |
|
696 def __call__(self, cls, *args, **kwargs): |
|
697 score = self.selector(cls, *args, **kwargs) |
|
698 return not score |
|
699 |
|
700 def __str__(self): |
|
701 return 'NOT(%s)' % super(NotSelector, self).__str__() |
688 |
702 |
689 # advanced selector building functions ######################################## |
703 # advanced selector building functions ######################################## |
690 |
704 |
691 def chainall(*selectors, **kwargs): |
705 def chainall(*selectors, **kwargs): |
692 """return a selector chaining given selectors. If one of |
706 """return a selector chaining given selectors. If one of |