# HG changeset patch # User Sylvain Thénault # Date 1269615241 -3600 # Node ID 1d9bef4a2b0c9c17c73c4d2181a7eca0c41627c5 # Parent fe52dd3936cf39977e2c97cf5e00619e1423bc5c [selectors] new is_in_state select to avoid common error when writing state based selector diff -r fe52dd3936cf -r 1d9bef4a2b0c selectors.py --- a/selectors.py Fri Mar 26 15:53:07 2010 +0100 +++ b/selectors.py Fri Mar 26 15:54:01 2010 +0100 @@ -1078,6 +1078,24 @@ return 1 return 0 +class is_in_state(score_entity): + """return 1 if entity is in one of the states given as argument list + + you should use this instead of your own score_entity x: x.state == 'bla' + selector to avoid some gotchas: + + * possible views gives a fake entity with no state + * you must use the latest tr info, not entity.state for repository side + checking of the current state + """ + def __init__(self, *states): + def score(entity, states=set(states)): + try: + return entity.latest_trinfo().new_state.name in states + except AttributeError: + return None + super(is_in_state, self).__init__(score) + ## deprecated stuff ############################################################