code: def _handle_output(self, ctx, component, arg, stage, role, config):
      from fate.arch import URI
  
      for output_pair_dict, artifacts in [
          (self.output_data, component.artifacts.data_outputs),
          (self.output_model, component.artifacts.model_outputs),
          (self.output_metric, component.artifacts.metric_outputs),
      ]:
          if allowed_artifacts := artifacts.get(arg):
              if allowed_artifacts.is_active_for(stage, role):
                  apply_spec: ArtifactOutputApplySpec = (
                      config.output_artifacts.get(arg)
                  )
                  if apply_spec is not None:
                      try:
                          if allowed_artifacts.is_multi:
                              if not apply_spec.is_template():
                                  raise ComponentArtifactApplyError(
                                      "template uri required for multiple output artifact"
                                  )
                              arti = allowed_artifacts.get_correct_arti(
                                  apply_spec
                              )
                              writers = WriterGenerator(
                                  component,
                                  arg,
                                  config,
                                  ctx,
                                  arti,
                                  apply_spec,
                              )
                              output_pair_dict[
                                  arg
                              ] = ComponentExecutionIO.OutputPair(
                                  artifact=writers.recorder,
                                  writer=writers,
                              )
  
                          else:
                              if apply_spec.is_template():
                                  raise ComponentArtifactApplyError(
                                      "template uri is not supported for non-multiple output artifact"
                                  )
                              arti = allowed_artifacts.get_correct_arti(
                                  apply_spec
                              )
                              writer = arti.get_writer(
                                  config,
                                  ctx,
                                  URI.from_string(apply_spec.uri),
                                  arti.get_type().type_name,
                              )
                              _update_source_meta(
                                  writer.artifact.metadata, config, arg
                              )
                              _maybe_update_model_overview_meta(
                                  writer.artifact.metadata,
                                  self.cpn,
                                  config,
                              )
                              output_pair_dict[
                                  arg
                              ] = ComponentExecutionIO.OutputPair(
                                  artifact=writer.artifact,
                                  writer=writer,
                              )
                      except Exception as e:
                          raise ComponentArtifactApplyError(
                              f"load as output artifact({allowed_artifacts}) error: {e}"
                          ) from e
                  elif allowed_artifacts.optional:
                      output_pair_dict[
                          arg
                      ] = ComponentExecutionIO.OutputPair(
                          artifact=None, writer=None
                      )
                  else:
                      raise ComponentArtifactApplyError(
                          f"load as output artifact({allowed_artifacts}) error: apply_config is None but not optional"
                      )
                  logger.debug(
                      f"apply artifact `{allowed_artifacts.name}`: {apply_spec} -> {output_pair_dict[arg].writer}"
                  )
                  return True
              else:
                  logger.debug(
                      f"skip artifact `{allowed_artifacts.name}` for stage `{stage}` and role `{role}`"
                  )
                  output_pair_dict[
                      arg
                  ] = ComponentExecutionIO.OutputPair(
                      artifact=None, writer=None
                  )
                  return True
      return False
  
imports: import logging
  import typing
  from typing import Dict, Generic, List, Optional, Union
  from fate.components.core.essential import Role, Stage
  from .artifacts._base_type import AT, MM, ArtifactDescribe, M, _ArtifactsType, _ArtifactType
label_desc: Use image node_id 4 for calling the ComponentExecutionIO obj's underlying member method code with example usage: obj._handle_output(ctx, component, arg, stage, role, config) and returns: False, True, True