How to use the simpleeval.AttributeDoesNotExist 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_dict_attr_access_disabled(self):
        # nested dict

        self.s.ATTR_INDEX_FALLBACK = False
        self.assertEqual(self.s.ATTR_INDEX_FALLBACK, False)

        self.s.names = {'a': {'b': {'c': 42}}}

        with self.assertRaises(simpleeval.AttributeDoesNotExist):
            self.t("a.b.c * 2", 84)

        self.t("a['b']['c'] * 2", 84)

        self.assertEqual(self.s.names['a']['b']['c'], 42)
github danthedeckie / simpleeval / test_simpleeval.py View on Github external
def test_attributedoesnotexist(self):
        try:
            raise AttributeDoesNotExist("foo", "foo in bar")
        except AttributeDoesNotExist as e:
            assert hasattr(e, 'attr')
            assert getattr(e, 'attr') == 'foo'
            assert hasattr(e, 'expression')
            assert getattr(e, 'expression') == 'foo in bar'
github danthedeckie / simpleeval / test_simpleeval.py View on Github external
with self.assertRaises(NameNotDefined):
            self.t("a == 2", None)

        self.s.names["s"] = 21

        with self.assertRaises(NameNotDefined):
            self.t("s += a", 21)

        self.s.names = None

        with self.assertRaises(InvalidExpression):
            self.t('s', 21)

        self.s.names = {'a': {'b': {'c': 42}}}

        with self.assertRaises(AttributeDoesNotExist):
            self.t('a.b.d**2', 42)
github danthedeckie / simpleeval / simpleeval.py View on Github external
# Maybe the base object is an actual object, not just a dict
        try:
            return getattr(node_evaluated, node.attr)
        except (AttributeError, TypeError):
            pass

        # TODO: is this a good idea?  Try and look for [x] if .x doesn't work?
        if self.ATTR_INDEX_FALLBACK:
            try:
                return node_evaluated[node.attr]
            except (KeyError, TypeError):
                pass

        # If it is neither, raise an exception
        raise AttributeDoesNotExist(node.attr, self.expr)