How to use the simpleeval.MAX_POWER 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 / test_simpleeval.py View on Github external
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 / 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 kororo / conff / conff / ee.py View on Github external
def load(fs_path: str, fs_root: str = '', errors: list = None, params: dict = None, opts: dict = None):
    errors = errors if type(errors) == list else []
    fs_file_path = os.path.join(fs_root, fs_path)
    fs_root = fs_root if fs_root is None else os.path.dirname(fs_file_path)
    params = params if params else {}
    opts = opts if opts else {
        'max_power': simpleeval.MAX_POWER,
        'max_string_length': simpleeval.MAX_STRING_LENGTH,
        'disallow_prefixes': simpleeval.DISALLOW_PREFIXES
    }
    try:
        with open(fs_file_path) as stream:
            # load_yaml initial structure
            data = yaml_safe_load(stream)
            data['_'] = data['_'] if data.get('_') else {}
            data_internal = {'fs_path': fs_path, 'fs_root': fs_root}
            data_internal = {**{'etype': 'fernet'}, **data_internal, **params}
            data['_'] = {**data['_'], **data_internal}
            names = {'R': data}
            fns = {}
            data = parse(data, names=names, fns=fns)
            # data cleanup to ensure no data_internal
            all(map(data['_'].pop, data_internal))
github kororo / conff / conff / parser.py View on Github external
from simpleeval import EvalWithCompoundTypes
from cryptography.fernet import Fernet
from conff import utils
from conff.utils import Munch2, update_recursive, yaml_safe_load, filter_value, odict


class Parser:
    # default params
    default_params = {
        'etype': 'fernet',
        # list of simpleeval library parameters
        'simpleeval': {
            # by default operators = simpleeval.DEFAULT_OPERATORS,
            'operators': {},
            'options': {
                'max_power': simpleeval.MAX_POWER,
                'max_string_length': simpleeval.MAX_STRING_LENGTH,
                'disallow_prefixes': simpleeval.DISALLOW_PREFIXES
            }
        }
    }

    def __init__(self, names=None, fns=None, params=None):
        """
        :param params: A dictionary containing some parameters that will modify
        how the builtin functions run. For example, the type of encryption to
        use and the encrpyption key to use or simpleeval library parameters
        """
        self.errors = []
        self.logger = self.prepare_logger()
        self.params = self.prepare_params(params=params)
        self.fns = self.prepare_functions(fns=fns)