class_docstr: Utility class to resolve Placeholder expressions.
  
  Placeholder expression is defined as a proto structure
  placeholder_pb2.PlaceholderExpression. It can be resolved with
  ResolutionContext to a concrete value.
class_docstr_tok: ["Utility","class","to","resolve","Placeholder","expressions",".","Placeholder","expression","is","defined","as","a","proto","structure","placeholder_pb2.PlaceholderExpression",".","It","can","be","resolved","with","ResolutionContext","to","a","concrete","value","."]
docstr: Evaluates the proto operator.
code: def _resolve_proto_operator(
      self, op: placeholder_pb2.ProtoOperator
  ) -> Any:
      """Evaluates the proto operator."""
      raw_message = self.resolve(op.expression)
      if raw_message is None:
          raise NullDereferenceError(op.expression)
  
      if isinstance(raw_message, str):
          value = proto_utils.deserialize_proto_message(
              raw_message,
              op.proto_schema.message_type,
              file_descriptors=op.proto_schema.file_descriptors,
          )
      elif isinstance(raw_message, message.Message):
          # Message such as platform config should not be encoded.
          value = raw_message
      else:
          raise ValueError(
              f"Got unsupported value type for proto operator: {type(raw_message)}."
          )
  
      if op.proto_field_path:
          for field in op.proto_field_path:
              if field.startswith("."):
                  try:
                      value = getattr(value, field[1:])
                  except AttributeError:
                      raise ValueError(
                          "While evaluting placeholder proto operator, "
                          f"got unknown proto field {field} on proto of "
                          f"type {type(value)}."
                      )
                  continue
              map_key = re.findall(r"\[['\"](.+)['\"]\]", field)
              if len(map_key) == 1:
                  try:
                      value = value[map_key[0]]
                  except KeyError:
                      raise ValueError(
                          "While evaluting placeholder proto operator, "
                          f"got unknown map field {field}."
                      )
                  continue
              # Going forward, index access for proto fields should be handled by
              # index op. This code here is kept to avoid breaking existing executor
              # specs.
              index = re.findall(r"\[(\d+)\]", field)
              if index and str.isdecimal(index[0]):
                  try:
                      value = value[int(index[0])]
                  except IndexError:
                      raise ValueError(
                          "While evaluting placeholder proto operator, "
                          f"got unknown index field {field}."
                      )
                  continue
              raise ValueError(
                  f"Got unsupported proto field path: {field}"
              )
  
      # Non-message primitive values are returned directly.
      if isinstance(value, (int, float, str, bool, bytes)):
          return value
  
      # Return repeated fields as list.
      # TODO(b/292040530): It was originally done with
      # if isinstance(value,(_message.RepeatedCompositeContainer,
      #    _message.RepeatedScalarContainer,
      #     containers.RepeatedCompositeFieldContainer,
      #     containers.RepeatedScalarFieldContainer))
      # however, it was not supported on an environment that Protoc
      # (google.protobuf.pyext._message) is not installed but only a pure Python
      # Protobuf presents. (ex. OSS macos Python 3.10) This is a new workaround
      # for pure Python users.
      if type(value).__name__ in (
          "RepeatedCompositeContainer",
          "RepeatedScalarContainer",
          "RepeatedCompositeFieldContainer",
          "RepeatedScalarFieldContainer",
      ):
          return list(value)
  
      if not isinstance(value, message.Message):
          raise ValueError(
              f"Got unsupported value type {type(value)} "
              "from accessing proto field path."
          )
  
      # For message-typed values, we need to consider serialization format.
      if op.serialization_format:
          if (
              op.serialization_format
              == placeholder_pb2.ProtoOperator.JSON
          ):
              return json_format.MessageToJson(
                  message=value,
                  sort_keys=True,
                  preserving_proto_field_name=True,
              )
          if (
              op.serialization_format
              == placeholder_pb2.ProtoOperator.TEXT_FORMAT
          ):
              return text_format.MessageToString(value)
          if (
              op.serialization_format
              == placeholder_pb2.ProtoOperator.INLINE_FILE_TEXT_FORMAT
          ):
              return fileio.get_inline_filename(
                  text_format.MessageToString(value, as_one_line=True)
              )
          if (
              op.serialization_format
              == placeholder_pb2.ProtoOperator.BINARY
          ):
              return value.SerializeToString()
  
      # Otherwise, just return the value as a proto. Note that the top-level
      # resolve_placeholder_expression() would reject this, but it can be a valid
      # intermediate value.
      return value
  
imports: import base64
  import enum
  import functools
  import os
  import re
  from typing import Any, Callable, Dict, List, Set, Union, cast
  from absl import logging
  import attr
  from tfx.dsl.io import fileio
  from tfx.orchestration.portable import data_types
  from tfx.proto.orchestration import placeholder_pb2
  from tfx.types import artifact
  from tfx.types import artifact_utils
  from tfx.types import value_artifact
  from tfx.utils import json_utils
  from tfx.utils import proto_utils
  from google.protobuf import any_pb2
  from google.protobuf import descriptor
  from google.protobuf import json_format
  from google.protobuf import message
  from google.protobuf import text_format
label_desc: Use image node_id 14 for calling the _ExpressionResolver obj's underlying member method code with example usage: obj._resolve_proto_operator(op) and returns: value, value, list, json_format, text_format, fileio, value