How to use the simpleeval.NameNotDefined 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_namenotdefined(self):
        try:
            raise NameNotDefined("foo", "foo in bar")
        except NameNotDefined as e:
            assert hasattr(e, 'name')
            assert getattr(e, 'name') == 'foo'
            assert hasattr(e, 'expression')
            assert getattr(e, 'expression') == 'foo in bar'
github danthedeckie / simpleeval / test_simpleeval.py View on Github external
def test_use_func(self):
        self.s = EvalWithCompoundTypes(functions={"map": map, "str": str})
        self.t('list(map(str, [-1, 0, 1]))', ['-1', '0', '1'])
        with self.assertRaises(NameNotDefined):
            self.s.eval('list(map(bad, [-1, 0, 1]))')

        with self.assertRaises(FunctionNotDefined):
            self.s.eval('dir(str)')
        with self.assertRaises(FeatureNotAvailable):
            self.s.eval('str.__dict__')

        self.s = EvalWithCompoundTypes(functions={"dir": dir, "str": str})
        self.t('dir(str)', dir(str))
github danthedeckie / simpleeval / test_simpleeval.py View on Github external
def test_no_leaking_names(self):
        # see issue #52, failing list comprehensions could leak locals
        with self.assertRaises(simpleeval.NameNotDefined):
            self.s.eval('[x if x == "2" else y for x in "123"]')

        with self.assertRaises(simpleeval.NameNotDefined):
            self.s.eval('x')
github danthedeckie / simpleeval / simpleeval.py View on Github external
# (the compiler rejects it, so you can't even
            # pass that to ast.parse)
            if hasattr(self.names, '__getitem__'):
                return self.names[node.id]
            elif callable(self.names):
                return self.names(node)
            else:
                raise InvalidExpression('Trying to use name (variable) "{0}"'
                                        ' when no "names" defined for'
                                        ' evaluator'.format(node.id))

        except KeyError:
            if node.id in self.functions:
                return self.functions[node.id]

            raise NameNotDefined(node.id, self.expr)
github KurtJacobson / hazzy / hazzy / main_old.py View on Github external
break

        factor = 1
        entry = widget.get_text().lower()
        if "in" in entry or '"' in entry:
            entry = entry.replace("in", "").replace('"', "")
            if self.stat.program_units != 1:
                factor = 25.4
        elif "mm" in entry:
            entry = entry.replace("mm", "")
            if self.stat.program_units != 2:
                factor = 1/25.4
        try:
            val = self.s.eval(entry) * factor
            self.set_work_offset(aletter, val)
        except (SyntaxError, simpleeval.NameNotDefined):
            msg = "{0} axis DRO entry '{1}' is not valid".format(aletter, entry)
            log.error(msg)
            self._show_message(["ERROR", msg])
        except Exception as e:
            log.exception(e)
            msg = "{0} axis DRO entry error, see log for details".format(aletter)
            self._show_message(["ERROR", msg])

        self.window.set_focus(None)