def read_from_which_host(client, pref, tag_sets=None):
 db = client.pymongo_test
 if isinstance(tag_sets, dict):
  tag_sets = [tag_sets]
 if tag_sets:
  tags = (tag_sets or pref.tag_sets)
  pref = pref.__class__(tags)
 db.read_preference = pref
 cursor = db.test.find()
 try:
  try:
   next(cursor)
  except StopIteration:
   pass
  return cursor.address
 except AutoReconnect:
  return None

def read_from_which_host ( client , pref , tag_sets = None ) : db = client . pymongo_test if isinstance ( tag_sets , dict ) : tag_sets = [ tag_sets ] if tag_sets : tags = ( tag_sets or pref . tag_sets ) pref = pref . __class__ ( tags ) db . read_preference = pref cursor = db . test . find ( ) try : try : next ( cursor ) except StopIteration : pass return cursor . address except AutoReconnect : return None
read from a client with the given read preference .