How to use the asteval.astutils.ExceptionHolder function in asteval

To help you get started, we’ve selected a few asteval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github newville / asteval / asteval / View on Github external
def raise_exception(self, node, exc=None, msg='', expr=None,
        """Add an exception."""
        if self.error is None:
            self.error = []
        if expr is None:
            expr = self.expr
        if len(self.error) > 0 and not isinstance(node, ast.Module):
            msg = '%s' % msg
        err = ExceptionHolder(node, exc=exc, msg=msg, expr=expr, lineno=lineno)
        self._interrupt = ast.Break()
        if self.error_msg is None:
            self.error_msg = "at expr='%s'" % (self.expr)
        elif len(msg) > 0:
            self.error_msg = msg
        if exc is None:
                exc = self.error[0].exc
                exc = RuntimeError
        raise exc(self.error_msg)