How to use the jinja.nodes.Expression function in Jinja

To help you get started, we’ve selected a few Jinja 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 pallets / jinja / jinja / nodes.py View on Github external
self.node = node
        self.name = name
        self.args = args

    def get_items(self):
        return [self.node, self.name] + list(self.args)

    def __repr__(self):
        return 'TestExpression(%r, %r, %r)' % (
            self.node,
            self.name,
            self.args
        )


class CallExpression(Expression):
    """
    {{ foo(bar) }}
    """

    def __init__(self, node, args, kwargs, dyn_args, dyn_kwargs,
                 lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.node = node
        self.args = args
        self.kwargs = kwargs
        self.dyn_args = dyn_args
        self.dyn_kwargs = dyn_kwargs

    def get_items(self):
        return [self.node, self.args, self.kwargs, self.dyn_args,
                self.dyn_kwargs]
github pallets / jinja / jinja / nodes.py View on Github external
def __init__(self, name, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.name = name

    def get_items(self):
        return [self.name]

    def allows_assignments(self):
        return self.name != '_'

    def __repr__(self):
        return 'NameExpression(%r)' % self.name


class ListExpression(Expression):
    """
    any list literal such as {{ [1, 2, 3] }}
    """

    def __init__(self, items, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.items = items

    def get_items(self):
        return list(self.items)

    def __repr__(self):
        return 'ListExpression(%r)' % (self.items,)


class DictExpression(Expression):
github pallets / jinja / jinja / nodes.py View on Github external
"""
    any constat such as {{ "foo" }}
    """

    def __init__(self, value, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.value = value

    def get_items(self):
        return [self.value]

    def __repr__(self):
        return 'ConstantExpression(%r)' % (self.value,)


class UndefinedExpression(Expression):
    """
    represents the special 'undefined' value.
    """

    def __repr__(self):
        return 'UndefinedExpression()'


class RegexExpression(Expression):
    """
    represents the regular expression literal.
    """

    def __init__(self, value, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.value = value
github pallets / jinja / jinja / nodes.py View on Github external
def get_items(self):
        return [self.node, self.args, self.kwargs, self.dyn_args,
                self.dyn_kwargs]

    def __repr__(self):
        return 'CallExpression(%r, %r, %r, %r, %r)' % (
            self.node,
            self.args,
            self.kwargs,
            self.dyn_args,
            self.dyn_kwargs
        )


class SubscriptExpression(Expression):
    """
    {{ foo.bar }} and {{ foo['bar'] }} etc.
    """

    def __init__(self, node, arg, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.node = node
        self.arg = arg

    def get_items(self):
        return [self.node, self.arg]

    def __repr__(self):
        return 'SubscriptExpression(%r, %r)' % (
            self.node,
            self.arg
github pallets / jinja / jinja / nodes.py View on Github external
Expression.__init__(self, lineno, filename)
        self.left = left
        self.right = right

    def get_items(self):
        return [self.left, self.right]

    def __repr__(self):
        return '%s(%r, %r)' % (
            self.__class__.__name__,
            self.left,
            self.right
        )


class UnaryExpression(Expression):
    """
    Baseclass for all unary expressions.
    """

    def __init__(self, node, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.node = node

    def get_items(self):
        return [self.node]

    def __repr__(self):
        return '%s(%r)' % (
            self.__class__.__name__,
            self.node
        )
github pallets / jinja / jinja / nodes.py View on Github external
"""
    any dict literal such as {{ {1: 2, 3: 4} }}
    """

    def __init__(self, items, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.items = items

    def get_items(self):
        return list(chain(*self.items))

    def __repr__(self):
        return 'DictExpression(%r)' % (self.items,)


class SetExpression(Expression):
    """
    any set literal such as {{ @(1, 2, 3) }}
    """

    def __init__(self, items, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.items = items

    def get_items(self):
        return self.items[:]

    def __repr__(self):
        return 'SetExpression(%r)' % (self.items,)


class ConditionalExpression(Expression):
github pallets / jinja / jinja / nodes.py View on Github external
def __init__(self, node, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.node = node

    def get_items(self):
        return [self.node]

    def __repr__(self):
        return '%s(%r)' % (
            self.__class__.__name__,
            self.node
        )


class ConstantExpression(Expression):
    """
    any constat such as {{ "foo" }}
    """

    def __init__(self, value, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.value = value

    def get_items(self):
        return [self.value]

    def __repr__(self):
        return 'ConstantExpression(%r)' % (self.value,)


class UndefinedExpression(Expression):
github pallets / jinja / jinja / nodes.py View on Github external
self.items = items

    def get_items(self):
        return list(self.items)

    def allows_assignments(self):
        for item in self.items:
            if not item.allows_assignments():
                return False
        return True

    def __repr__(self):
        return 'TupleExpression(%r)' % (self.items,)


class ConcatExpression(Expression):
    """
    For {{ foo ~ bar }}. Because of various reasons (especially because
    unicode conversion takes place for the left and right expression and
    is better optimized that way)
    """

    def __init__(self, args, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.args = args

    def get_items(self):
        return list(self.args)

    def __repr__(self):
        return 'ConcatExpression(%r)' % (self.items,)
github pallets / jinja / jinja / nodes.py View on Github external
def __init__(self, node, arg, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.node = node
        self.arg = arg

    def get_items(self):
        return [self.node, self.arg]

    def __repr__(self):
        return 'SubscriptExpression(%r, %r)' % (
            self.node,
            self.arg
        )


class SliceExpression(Expression):
    """
    1:2:3 etc.
    """

    def __init__(self, start, stop, step, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.start = start
        self.stop = stop
        self.step = step

    def get_items(self):
        return [self.start, self.stop, self.step]

    def __repr__(self):
        return 'SliceExpression(%r, %r, %r)' % (
            self.start,
github pallets / jinja / jinja / nodes.py View on Github external
self.test = test
        self.expr1 = expr1
        self.expr2 = expr2

    def get_items(self):
        return [self.test, self.expr1, self.expr2]

    def __repr__(self):
        return 'ConstantExpression(%r, %r, %r)' % (
            self.test,
            self.expr1,
            self.expr2
        )


class FilterExpression(Expression):
    """
    {{ foo|bar|baz }}
    """

    def __init__(self, node, filters, lineno=None, filename=None):
        Expression.__init__(self, lineno, filename)
        self.node = node
        self.filters = filters

    def get_items(self):
        result = [self.node]
        for filter, args in self.filters:
            result.append(filter)
            result.extend(args)
        return result