code: def get_output_handler(
      output_type: str, output_fname: Optional[str] = None
  ) -> "OutputHandler":
      """
  
      :param output_type: Type of output handler.
      :param output_fname: Output filename. If none sys.stdout is used.
      :raises: ValueError for unknown output_type.
      :return: Output handler.
      """
      output_stream = (
          sys.stdout
          if output_fname is None
          else smart_open(output_fname, mode="w")
      )
      if output_type == C.OUTPUT_HANDLER_TRANSLATION:
          return StringOutputHandler(output_stream)
      elif output_type == C.OUTPUT_HANDLER_SCORE:
          return ScoreOutputHandler(output_stream)
      elif output_type == C.OUTPUT_HANDLER_PAIR_WITH_SCORE:
          return PairWithScoreOutputHandler(output_stream)
      elif output_type == C.OUTPUT_HANDLER_TRANSLATION_WITH_SCORE:
          return StringWithScoreOutputHandler(output_stream)
      elif output_type == C.OUTPUT_HANDLER_BENCHMARK:
          return BenchmarkOutputHandler(output_stream)
      elif output_type == C.OUTPUT_HANDLER_JSON:
          return JSONOutputHandler(output_stream)
      elif output_type == C.OUTPUT_HANDLER_TRANSLATION_WITH_FACTORS:
          return FactoredStringOutputHandler(output_stream)
      else:
          raise ValueError("unknown output type")
  
imports: import json
  import sys
  from abc import ABC, abstractmethod
  from itertools import chain
  from typing import Optional
  import sockeye.constants
  from sockeye.utils import smart_open
  from .None import inference
label_desc: Use image node_id 1 for calling a global function with example usage: get_output_handler(output_type, output_fname) and returns: StringOutputHandler, ScoreOutputHandler, PairWithScoreOutputHandler, StringWithScoreOutputHandler, BenchmarkOutputHandler, JSONOutputHandler, FactoredStringOutputHandler