Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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