def _with_primary(max_staleness, selection):
 primary = selection.primary
 sds = []
 for s in selection.server_descriptions:
  if (s.server_type == SERVER_TYPE.RSSecondary):
   staleness = (((s.last_update_time - s.last_write_date) - (primary.last_update_time - primary.last_write_date)) + selection.heartbeat_frequency)
   if (staleness <= max_staleness):
    sds.append(s)
  else:
   sds.append(s)
 return selection.with_server_descriptions(sds)

def _with_primary ( max_staleness , selection ) : primary = selection . primary sds = [ ] for s in selection . server_descriptions : if ( s . server_type == SERVER_TYPE . RSSecondary ) : staleness = ( ( ( s . last_update_time - s . last_write_date ) - ( primary . last_update_time - primary . last_write_date ) ) + selection . heartbeat_frequency ) if ( staleness <= max_staleness ) : sds . append ( s ) else : sds . append ( s ) return selection . with_server_descriptions ( sds )
apply max_staleness .