'In pymongo <= 1.9, even with slave_okay set, we will re-route to master if the secondary we\'re talking to goes down - this should work around that'

def isValidMonitorConn(self, hostKey, conn):

    if (not conn):
        return False
    hostDef = None
    self.serverHostDefsLock.acquire()
    try:
        if (hostKey in self.serverHostDefs):
            hostDef = self.serverHostDefs[hostKey]
    finally:
        self.serverHostDefsLock.release()
    if (not hostDef):
        return False
    if (conn.host is not None):
        if ((conn.host != hostDef['hostname']) or (str(conn.port) != str(hostDef['port']))):
            self.logger.warning(((((('replica    set    switched    hosts,    disconnecting    -    wanted:    ' + str(hostDef['mongoUri'])) + '    -    got:    mongodb://') + str(conn.host)) + ':') + str(conn.port)))
            if (conn is not None):
                conn.disconnect()
            return False
        else:
            return True
    else:
        return True
