How to use the jinja.nodes.ConstantExpression 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 / parser.py View on Github external
def parse_subscript_expression(self, node):
        """
        Parse a subscript statement. Gets attributes and items from an
        object.
        """
        lineno = self.stream.lineno
        if self.stream.current.type == 'dot':
            self.stream.next()
            token = self.stream.current
            if token.type in ('name', 'integer'):
                arg = nodes.ConstantExpression(token.value, token.lineno,
                                               self.filename)
            else:
                raise TemplateSyntaxError('expected name or number',
                                          token.lineno, self.filename)
            self.stream.next()
        elif self.stream.current.type == 'lbracket':
            self.stream.next()
            args = []
            while self.stream.current.type != 'rbracket':
                if args:
                    self.stream.expect('comma')
                args.append(self.parse_subscribed_expression())
            self.stream.expect('rbracket')
            if len(args) == 1:
                arg = args[0]
            else:
github pallets / jinja / jinja / parser.py View on Github external
def parse_none_expression(self):
        """
        Parse a none literal.
        """
        token = self.stream.expect('name', 'none')
        return nodes.ConstantExpression(None, token.lineno, self.filename)
github pallets / jinja / jinja / translators / python.py View on Github external
nodes.IfCondition:              self.handle_if_condition,
            nodes.Cycle:                    self.handle_cycle,
            nodes.Print:                    self.handle_print,
            nodes.Macro:                    self.handle_macro,
            nodes.Call:                     self.handle_call,
            nodes.Set:                      self.handle_set,
            nodes.Filter:                   self.handle_filter,
            nodes.Block:                    self.handle_block,
            nodes.Include:                  self.handle_include,
            nodes.Trans:                    self.handle_trans,

            # expression nodes
            nodes.NameExpression:           self.handle_name,
            nodes.CompareExpression:        self.handle_compare,
            nodes.TestExpression:           self.handle_test,
            nodes.ConstantExpression:       self.handle_const,
            nodes.RegexExpression:          self.handle_regex,
            nodes.SubscriptExpression:      self.handle_subscript,
            nodes.FilterExpression:         self.handle_filter_expr,
            nodes.CallExpression:           self.handle_call_expr,
            nodes.AddExpression:            self.handle_add,
            nodes.SubExpression:            self.handle_sub,
            nodes.ConcatExpression:         self.handle_concat,
            nodes.DivExpression:            self.handle_div,
            nodes.FloorDivExpression:       self.handle_floor_div,
            nodes.MulExpression:            self.handle_mul,
            nodes.ModExpression:            self.handle_mod,
            nodes.PosExpression:            self.handle_pos,
            nodes.NegExpression:            self.handle_neg,
            nodes.PowExpression:            self.handle_pow,
            nodes.DictExpression:           self.handle_dict,
            nodes.SetExpression:            self.handle_set_expr,
github pallets / jinja / jinja / parser.py View on Github external
def parse_bool_expression(self):
        """
        Parse a boolean literal.
        """
        token = self.stream.expect('name')
        if token.value == 'true':
            value = True
        elif token.value == 'false':
            value = False
        else:
            raise TemplateSyntaxError("expected boolean literal",
                                      token.lineno, self.filename)
        return nodes.ConstantExpression(value, token.lineno, self.filename)
github pallets / jinja / jinja / utils.py View on Github external
return value is a list of tuples in the form ``(lineno, singular,
    plural)``. If a translation doesn't require a plural form the
    third item is `None`.
    """
    todo = [ast]
    result = []
    while todo:
        node = todo.pop()
        if node.__class__ is nodes.Trans:
            result.append((node.lineno, node.singular, node.plural))
        elif node.__class__ is nodes.CallExpression and \
             node.node.__class__ is nodes.NameExpression and \
             node.node.name == '_':
            if len(node.args) == 1 and not node.kwargs and not node.dyn_args \
               and not node.dyn_kwargs and \
               node.args[0].__class__ is nodes.ConstantExpression:
                result.append((node.lineno, node.args[0].value, None))
        todo.extend(node.get_child_nodes())
    result.sort(lambda a, b: cmp(a[0], b[0]))
    return result
github pallets / jinja / jinja / parser.py View on Github external
def parse_number_expression(self):
        """
        Parse a number literal.
        """
        token = self.stream.current
        if token.type not in ('integer', 'float'):
            raise TemplateSyntaxError('integer or float literal expected',
                                      token.lineno, self.filename)
        self.stream.next()
        return nodes.ConstantExpression(token.value, token.lineno, self.filename)