Beispiel #1
0
    def __init__(self, args: str = "", name: str = "_") -> None:
        super().__init__(args, name)
        if not self.args.expr:
            self.parser.error("the following arguments are required: expr")

        try:
            self.code = compile(" ".join(self.args.expr), "<string>", "eval")
        except SyntaxError as err:
            raise sdb.CommandEvalSyntaxError(self.name, err)
Beispiel #2
0
    def __init__(self,
                 prog: drgn.Program,
                 args: str = "",
                 name: str = "_") -> None:
        super().__init__(prog, args, name)
        if not self.args.expr:
            self.parser.error("the following arguments are required: expr")

        index = None
        operators = ["==", "/=", ">", "<", ">=", "<="]
        for operator in operators:
            try:
                index = self.args.expr.index(operator)
                # Use the first comparison operator we find.
                break
            except ValueError:
                continue

        if index is None:
            # If the comparison index is still None, this means not
            # operator was found. This is an error.
            raise sdb.CommandInvalidInputError(
                self.name, "comparison operator is missing")

        if index == 0:
            # If the comparison index is found to be 0, this means
            # there's no left hand side of the comparison to compare the
            # right hand side to. This is an error.
            raise sdb.CommandInvalidInputError(
                self.name, "left hand side of expression is missing")

        if index == len(self.args.expr) - 1:
            # If the index is found to be at the very end of the list,
            # this means there's no right hand side of the comparison to
            # compare the left hand side to. This is an error.
            raise sdb.CommandInvalidInputError(
                self.name, "right hand side of expression is missing")

        try:
            self.lhs_code = compile(" ".join(self.args.expr[:index]),
                                    "<string>", "eval")
            self.rhs_code = compile(" ".join(self.args.expr[index + 1:]),
                                    "<string>", "eval")
        except SyntaxError as err:
            raise sdb.CommandEvalSyntaxError(self.name, err)

        self.compare = self.args.expr[index]
        if self.compare == "/=":
            self.compare = "!="
Beispiel #3
0
    def __init__(self,
                 args: Optional[List[str]] = None,
                 name: str = "_") -> None:
        super().__init__(args, name)
        self.expr = self.args.expr[0].split()

        index = None
        operators = ["==", "!=", ">", "<", ">=", "<="]
        for operator in operators:
            try:
                index = self.expr.index(operator)
                # Use the first comparison operator we find.
                break
            except ValueError:
                continue

        if index is None:
            # If the comparison index is still None, this means not
            # operator was found. This is an error.
            raise sdb.CommandInvalidInputError(
                self.name, "comparison operator is missing")

        if index == 0:
            # If the comparison index is found to be 0, this means
            # there's no left hand side of the comparison to compare the
            # right hand side to. This is an error.
            raise sdb.CommandInvalidInputError(
                self.name, "left hand side of expression is missing")

        if index == len(self.expr) - 1:
            # If the index is found to be at the very end of the list,
            # this means there's no right hand side of the comparison to
            # compare the left hand side to. This is an error.
            raise sdb.CommandInvalidInputError(
                self.name, "right hand side of expression is missing")

        try:
            self.lhs_code = compile(" ".join(self.expr[:index]), "<string>",
                                    "eval")
            self.rhs_code = compile(" ".join(self.expr[index + 1:]), "<string>",
                                    "eval")
        except SyntaxError as err:
            raise sdb.CommandEvalSyntaxError(self.name, err)

        self.compare = self.expr[index]