#NEWLINE# def select_member( members , mode = ReadPreference . PRIMARY , tag_sets = None , latency = 15 ) : #NEWLINE# #INDENT# 'Return a Member or None.\n    ' #NEWLINE# if ( tag_sets is None ) : #NEWLINE# #INDENT# tag_sets = [ { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ] #NEWLINE# #UNINDENT# PRIMARY = ReadPreference . PRIMARY #NEWLINE# PRIMARY_PREFERRED = ReadPreference . PRIMARY_PREFERRED #NEWLINE# SECONDARY = ReadPreference . SECONDARY #NEWLINE# SECONDARY_PREFERRED = ReadPreference . SECONDARY_PREFERRED #NEWLINE# NEAREST = ReadPreference . NEAREST #NEWLINE# if ( mode == PRIMARY ) : #NEWLINE# #INDENT# if ( tag_sets != [ { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ] ) : #NEWLINE# #INDENT# raise ConfigurationError ( 'PRIMARY cannot be combined with tags' ) #NEWLINE# #UNINDENT# return select_primary ( members ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == PRIMARY_PREFERRED ) : #NEWLINE# #INDENT# candidate_primary = select_member ( members , PRIMARY , [ { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ] , latency ) #NEWLINE# if candidate_primary : #NEWLINE# #INDENT# return candidate_primary #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return select_member ( members , SECONDARY , tag_sets , latency ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == SECONDARY ) : #NEWLINE# #INDENT# for tags in tag_sets : #NEWLINE# #INDENT# candidate = select_member_with_tags ( members , tags , True , latency ) #NEWLINE# if candidate : #NEWLINE# #INDENT# return candidate #NEWLINE# #UNINDENT# #UNINDENT# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == SECONDARY_PREFERRED ) : #NEWLINE# #INDENT# candidate_secondary = select_member ( members , SECONDARY , tag_sets , latency ) #NEWLINE# if candidate_secondary : #NEWLINE# #INDENT# return candidate_secondary #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return select_member ( members , PRIMARY , [ { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ] , latency ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == NEAREST ) : #NEWLINE# #INDENT# for tags in tag_sets : #NEWLINE# #INDENT# candidate = select_member_with_tags ( members , tags , False , latency ) #NEWLINE# if candidate : #NEWLINE# #INDENT# return candidate #NEWLINE# #UNINDENT# #UNINDENT# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ConfigurationError ( ( 'Invalid mode %s' % repr ( mode ) ) )