human
Complete this python program:
def instance_processor(mapper, context, path, adapter, polymorphic_from=None, only_load_props=None, refresh_state=None, polymorphic_discriminator=None):
assistant
#Here is the Python program you requested.

    """Produce a mapper level row processor callable
    which processes rows into mapped instances.
    """
    pk_cols = mapper.primary_key
    if (polymorphic_from or refresh_state):
        polymorphic_on = None
    else:
        if (polymorphic_discriminator is not None):
            polymorphic_on = polymorphic_discriminator
        else:
            polymorphic_on = mapper.polymorphic_on
        polymorphic_instances = util.PopulateDict(_configure_subclass_mapper(mapper, context, path, adapter))
    version_id_col = mapper.version_id_col
    if adapter:
        pk_cols = [adapter.columns[c] for c in pk_cols]
        if (polymorphic_on is not None):
            polymorphic_on = adapter.columns[polymorphic_on]
        if (version_id_col is not None):
            version_id_col = adapter.columns[version_id_col]
    identity_class = mapper._identity_class
    new_populators = []
    existing_populators = []
    eager_populators = []
    load_path = ((context.query._current_path + path) if context.query._current_path.path else path)
    def populate_state(state, dict_, row, isnew, only_load_props):
        if isnew:
            if context.propagate_options:
                state.load_options = context.propagate_options
            if state.load_options:
                state.load_path = load_path
        if (not new_populators):
            _populators(mapper, context, path, row, adapter, new_populators, existing_populators, eager_populators)
        if isnew:
            populators = new_populators
        else:
            populators = existing_populators
        if (only_load_props is None):
            for (key, populator) in populators:
                populator(state, dict_, row)
        elif only_load_props:
            for (key, populator) in populators:
                if (key in only_load_props):
                    populator(state, dict_, row)
    session_identity_map = context.session.identity_map
    listeners = mapper.dispatch
    translate_row = (listeners.translate_row or None)
    create_instance = (listeners.create_instance or None)
    populate_instance = (listeners.populate_instance or None)
  ...