Esempio n. 1
0
 def get_condition_value(self, condition, raise_on_missing=True):
     if 'value' in condition.attrib:
         value_node = TemplateNode()
         value_node.append(TemplateWordNode(condition.attrib['value']))
         return value_node
         #return condition.attrib['value']
     else:
         values = condition.findall('value')
         if len(values) == 0:
             if raise_on_missing is True:
                 raise ParserException("Error, element has no value",
                                       xml_element=condition)
             else:
                 return None
         elif len(values) > 1:
             if raise_on_missing is True:
                 raise ParserException(
                     "Error, element has multiple value elements",
                     xml_element=condition)
             else:
                 return None
         else:
             value_node = TemplateNode()
             self.parse_template_node(values[0], value_node)
             return value_node
Esempio n. 2
0
    def parse_bot_expression(self, expression, branch):

        bot_node = TemplateBotNode()
        branch.children.append(bot_node)

        name_found = False

        if 'name' in expression.attrib:
            node = TemplateNode()
            name_node = TemplateWordNode(expression.attrib['name'])
            node.append(name_node)
            name_found = True
            bot_node.name = node

        self.parse_text(self.get_text_from_element(expression), bot_node)

        for child in expression:

            if child.tag == 'name':
                node = TemplateNode()
                self.parse_text(self.get_text_from_element(child), node)
                for sub_child in child:
                    self.parse_tag_expression(sub_child, node)
                    self.parse_text(self.get_text_from_element(child), node)

                bot_node.name = node
                name_found = True

            else:
                self.parse_tag_expression(child, bot_node)

            self.parse_text(self.get_tail_from_element(child), bot_node)

        if name_found is False:
            raise ParserException("Error, name not found", xml_element=expression)
Esempio n. 3
0
    def parse_get_expression(self, expression, branch):

        get_node = TemplateGetNode()
        branch.children.append(get_node)

        name_found = False
        var_found = False

        if 'name' in expression.attrib:
            node = TemplateNode()
            name_node = TemplateWordNode(expression.attrib['name'])
            node.append(name_node)
            get_node.local = False
            name_found = True
            get_node.name = node

        if 'var' in expression.attrib:
            node = TemplateNode()
            var_node = TemplateWordNode(expression.attrib['var'])
            node.append(var_node)
            get_node.local = True
            var_found = True
            get_node.name = node

        for child in expression:

            if child.tag == 'name':
                node = TemplateNode()

                self.parse_text(self.get_text_from_element(child), node)
                for sub_child in child:
                    self.parse_tag_expression(sub_child, node)
                    self.parse_text(self.get_text_from_element(child), node)

                get_node.name = node
                get_node.local = False
                name_found = True

            elif child.tag == 'var':
                node = TemplateNode()

                self.parse_text(self.get_text_from_element(child), node)
                for sub_child in child:
                    self.parse_tag_expression(sub_child, node)
                    self.parse_text(self.get_text_from_element(child), node)

                get_node.name = node
                get_node.local = True
                var_found = True

            else:
                raise ParserException("Error, invalid get",
                                      xml_element=expression)

        if name_found is True and var_found is True:
            raise ParserException(
                "Error, get node has both name AND var values",
                xml_element=expression)