Example #1
0
    def _ParseTaggingFile(self, tag_file_path):
        """Parses tag definitions from the source.

    Args:
      tag_file_path (str): path to the tag file.

    Returns:
      efilter.ast.Expression: efilter abstract syntax tree (AST), containing the
          tagging rules.
    """
        tags = []
        for label_name, rules in self._ParseDefinitions(tag_file_path):
            if not rules:
                logging.warning(
                    u'All rules for label "{0:s}" are invalid.'.format(
                        label_name))
                continue

            tag = efilter_ast.IfElse(
                # Union will be true if any of the 'rules' match.
                efilter_ast.Union(*[rule.root for rule in rules]),
                # If so then evaluate to a string with the name of the tag.
                efilter_ast.Literal(label_name),
                # Otherwise don't return anything.
                efilter_ast.Literal(None))
            tags.append(tag)

        # Generate a repeated value with all the tags (None will be skipped).
        return efilter_ast.Repeat(*tags)
Example #2
0
File: tag.py Project: rlugojr/dotty
    def parse(self):
        tags = []
        for tag_name, rules in self._parse_tagfile():
            tag = ast.IfElse(
                # Union will be true if any of the 'rules' match.
                ast.Union(*[rule.root for rule in rules]),
                # If so then evaluate to a string with the name of the tag.
                ast.Literal(tag_name),
                # Otherwise don't return anything.
                ast.Literal(None))
            tags.append(tag)

        self.original.close()
        # Generate a repeated value with all the tags (None will be skipped).
        return ast.Repeat(*tags)
Example #3
0
    def testOperatorPrecedence(self):
        # Prefix operator, like the unary minus sign, should respect operator
        # precedence order.
        self.assertQueryMatches(
            "-x + y",
            ast.Sum(ast.Product(ast.Literal(-1), ast.Var("x")), ast.Var("y")))

        self.assertQueryMatches(
            "not x and y",
            ast.Intersection(ast.Complement(ast.Var("x")), ast.Var("y")))

        self.assertQueryMatches(
            "x / -f(y) or not z(a, b)",
            ast.Union(
                ast.Quotient(
                    ast.Var("x"),
                    ast.Product(ast.Literal(-1),
                                ast.Apply(ast.Var("f"), ast.Var("y")))),
                ast.Complement(
                    ast.Apply(ast.Var("z"), ast.Var("a"), ast.Var("b")))))
Example #4
0
    def GetEventTaggingRules(self):
        """Retrieves the event tagging rules from the tagging file.

    Returns:
      efilter.ast.Expression: efilter abstract syntax tree (AST), containing the
          tagging rules.
    """
        tags = []
        for label_name, rules in self._ParseDefinitions(self._path):
            if not rules:
                continue

            tag = efilter_ast.IfElse(
                # Union will be true if any of the 'rules' match.
                efilter_ast.Union(*[rule.root for rule in rules]),
                # If so then evaluate to a string with the name of the tag.
                efilter_ast.Literal(label_name),
                # Otherwise don't return anything.
                efilter_ast.Literal(None))
            tags.append(tag)

        # Generate a repeated value with all the tags (None will be skipped).
        return efilter_ast.Repeat(*tags)