selectors.py
branchstable
changeset 5044 1d9bef4a2b0c
parent 4833 41a78fb4107c
child 5094 13b7f30db0bb
equal deleted inserted replaced
5043:fe52dd3936cf 5044:1d9bef4a2b0c
  1076             return 1
  1076             return 1
  1077         if transition is not None and getattr(transition, 'name', None) in self.expected:
  1077         if transition is not None and getattr(transition, 'name', None) in self.expected:
  1078             return 1
  1078             return 1
  1079         return 0
  1079         return 0
  1080 
  1080 
       
  1081 class is_in_state(score_entity):
       
  1082     """return 1 if entity is in one of the states given as argument list
       
  1083 
       
  1084     you should use this instead of your own score_entity x: x.state == 'bla'
       
  1085     selector to avoid some gotchas:
       
  1086 
       
  1087     * possible views gives a fake entity with no state
       
  1088     * you must use the latest tr info, not entity.state for repository side
       
  1089       checking of the current state
       
  1090     """
       
  1091     def __init__(self, *states):
       
  1092         def score(entity, states=set(states)):
       
  1093             try:
       
  1094                 return entity.latest_trinfo().new_state.name in states
       
  1095             except AttributeError:
       
  1096                 return None
       
  1097         super(is_in_state, self).__init__(score)
       
  1098 
  1081 
  1099 
  1082 ## deprecated stuff ############################################################
  1100 ## deprecated stuff ############################################################
  1083 
  1101 
  1084 entity_implements = class_renamed('entity_implements', implements)
  1102 entity_implements = class_renamed('entity_implements', implements)
  1085 
  1103