def bulk_replace(values, existing_adapter, new_adapter):
 assert isinstance(values, list)
 idset = util.IdentitySet
 existing_idset = idset((existing_adapter or ()))
 constants = existing_idset.intersection((values or ()))
 additions = idset((values or ())).difference(constants)
 removals = existing_idset.difference(constants)
 appender = new_adapter.bulk_appender()
 for member in (values or ()):
  if (member in additions):
   appender(member)
  elif (member in constants):
   appender(member, _sa_initiator=False)
 if existing_adapter:
  remover = existing_adapter.bulk_remover()
  for member in removals:
   remover(member)

def bulk_replace ( values , existing_adapter , new_adapter ) : assert isinstance ( values , list ) idset = util . IdentitySet existing_idset = idset ( ( existing_adapter or ( ) ) ) constants = existing_idset . intersection ( ( values or ( ) ) ) additions = idset ( ( values or ( ) ) ) . difference ( constants ) removals = existing_idset . difference ( constants ) appender = new_adapter . bulk_appender ( ) for member in ( values or ( ) ) : if ( member in additions ) : appender ( member ) elif ( member in constants ) : appender ( member , _sa_initiator = False ) if existing_adapter : remover = existing_adapter . bulk_remover ( ) for member in removals : remover ( member )
load a new collection .