from parlai.agents.programr.parser.template.nodes.base import TemplateNode
from parlai.agents.programr.utils.logging.ylogger import YLogger


class TemplateImageNode(TemplateNode):

    def __init__(self):
        super().__init__()

    def resolve_to_string(self, brain):
        str = "<image>%s</image>"%self.resolve_children_to_string(brain)
        return str

    def resolve(self, brain):
        try:
            return self.resolve_to_string(brain)
        except Exception as excep:
            YLogger.exception(brain, "Failed to resolve", excep)
            return ""

    def to_string(self):
        return "[IMAGE] %d" % (len(self._children))

    def to_xml(self, client_context):
        return self.resolve_to_string(client_context)

    #######################################################################################################
    #
    def parse_expression(self, graph, expression):
        self._parse_node(graph, expression)

