#NEWLINE# def select_member_with_tags( members , tags , secondary_only , latency ) : #NEWLINE# #INDENT# candidates = [ ] #NEWLINE# for candidate in members : #NEWLINE# #INDENT# if ( secondary_only and candidate . is_primary ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not ( candidate . is_primary or candidate . is_secondary ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if candidate . matches_tags ( members ) : #NEWLINE# #INDENT# candidates . append ( candidate ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not candidates ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# fastest = min ( [ candidate . get_avg_ping_time ( ) for candidate in candidates ] ) #NEWLINE# near_candidates = [ candidate for candidate in candidates if ( ( candidate . get_avg_ping_time ( ) - fastest ) < ( latency / 1000.0 ) ) ] #NEWLINE# return random . choice ( near_candidates )