#NEWLINE# def read_from_which_host( client , pref , tag_sets = None ) : #NEWLINE# #INDENT# "Read from a client with the given Read Preference.\n\n    Return the 'host:port' which was read from.\n\n    :Parameters:\n      - `client`: A MongoClient\n      - `mode`: A ReadPreference\n      - `tag_sets`: List of dicts of tags for data-center-aware reads\n    " #NEWLINE# db = client . pymongo_test #NEWLINE# if isinstance ( tag_sets , dict ) : #NEWLINE# #INDENT# tag_sets = [ tag_sets ] #NEWLINE# #UNINDENT# if tag_sets : #NEWLINE# #INDENT# tags = ( tag_sets or pref . tag_sets ) #NEWLINE# pref = pref . __class__ ( tags ) #NEWLINE# #UNINDENT# db . read_preference = pref #NEWLINE# cursor = db . test . find ( ) #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# next ( cursor ) #NEWLINE# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return cursor . address #NEWLINE# #UNINDENT# except AutoReconnect : #NEWLINE# #INDENT# return None