How to use the simpleeval.NumberTooHigh function in simpleeval

To help you get started, we’ve selected a few simpleeval 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 danthedeckie / simpleeval / test_simpleeval.py View on Github external
def test_long_running(self):
        """ exponent operations can take a long time. """
        old_max = simpleeval.MAX_POWER

        self.t("9**9**5", 9 ** 9 ** 5)

        with self.assertRaises(simpleeval.NumberTooHigh):
            self.t("9**9**8", 0)

        # and does limiting work?

        simpleeval.MAX_POWER = 100

        with self.assertRaises(simpleeval.NumberTooHigh):
            self.t("101**2", 0)

        # good, so set it back:

        simpleeval.MAX_POWER = old_max
github danthedeckie / simpleeval / simpleeval.py View on Github external
def safe_power(a, b):  # pylint: disable=invalid-name
    """ a limited exponent/to-the-power-of function, for safety reasons """

    if abs(a) > MAX_POWER or abs(b) > MAX_POWER:
        raise NumberTooHigh("Sorry! I don't want to evaluate {0} ** {1}"
                            .format(a, b))
    return a ** b