vregistry.py
branchtls-sprint
changeset 631 99f5852f8604
parent 630 66ff0b2f7d03
child 646 8a9551089912
equal deleted inserted replaced
630:66ff0b2f7d03 631:99f5852f8604
   511 set_log_methods(registerer, getLogger('cubicweb.registration'))
   511 set_log_methods(registerer, getLogger('cubicweb.registration'))
   512 
   512 
   513 
   513 
   514 # advanced selector building functions ########################################
   514 # advanced selector building functions ########################################
   515 
   515 
   516 def chainall(*selectors):
   516 def chainall(*selectors, **kwargs):
   517     """return a selector chaining given selectors. If one of
   517     """return a selector chaining given selectors. If one of
   518     the selectors fail, selection will fail, else the returned score
   518     the selectors fail, selection will fail, else the returned score
   519     will be the sum of each selector'score
   519     will be the sum of each selector'score
   520     """
   520     """
   521     assert selectors
   521     assert selectors
   525             partscore = selector(cls, *args, **kwargs)
   525             partscore = selector(cls, *args, **kwargs)
   526             if not partscore:
   526             if not partscore:
   527                 return 0
   527                 return 0
   528             score += partscore
   528             score += partscore
   529         return score
   529         return score
       
   530     if 'name' in kwargs:
       
   531         selector.__name__ = kwargs['name']
   530     return selector
   532     return selector
   531 
   533 
   532 def chainfirst(*selectors):
   534 def chainfirst(*selectors, **kwargs):
   533     """return a selector chaining given selectors. If all
   535     """return a selector chaining given selectors. If all
   534     the selectors fail, selection will fail, else the returned score
   536     the selectors fail, selection will fail, else the returned score
   535     will be the first non-zero selector score
   537     will be the first non-zero selector score
   536     """
   538     """
   537     assert selectors
   539     assert selectors
   539         for selector in selectors:
   541         for selector in selectors:
   540             partscore = selector(cls, *args, **kwargs)
   542             partscore = selector(cls, *args, **kwargs)
   541             if partscore:
   543             if partscore:
   542                 return partscore
   544                 return partscore
   543         return 0
   545         return 0
       
   546     if 'name' in kwargs:
       
   547         selector.__name__ = kwargs['name']
   544     return selector
   548     return selector
   545 
   549 
   546 
   550 
   547 # selector base classes and operations ########################################
   551 # selector base classes and operations ########################################
       
   552 
   548 class Selector(object):
   553 class Selector(object):
   549     """base class for selector classes providing implementation
   554     """base class for selector classes providing implementation
   550     for operators ``&`` and ``|``
   555     for operators ``&`` and ``|``
   551 
   556 
   552     This class is only here to give access to binary operators, the
   557     This class is only here to give access to binary operators, the