Python jinja2.nodes 模块,ContextReference() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用jinja2.nodes.ContextReference()

项目:pyramid_webpack    作者:stevearc    | 项目源码 | 文件源码
def parse(self, parser):
        # the first token is the token that started the tag.  In our case
        # we only listen to ``'webpack'`` so this will be a name token with
        # `webpack` as value.  We get the line number so that we can give
        # that line number to the nodes we create by hand.
        lineno = six.next(parser.stream).lineno
        ctx_ref = nodes.ContextReference()

        # Parse a single expression that is the 'bundle' or 'config:bundle'
        args = [ctx_ref, parser.parse_expression()]

        # if there is a comma, the user provided an 'extensions' arg
        if parser.stream.skip_if('comma'):
            args.append(parser.parse_expression())
        else:
            args.append(nodes.Const(None))

        # now we parse the body of the cache block up to `endwebpack` and
        # drop the needle (which would always be `endwebpack` in that case)
        body = parser.parse_statements(['name:endwebpack'], drop_needle=True)

        call_args = [nodes.Name('ASSET', 'param')]

        return nodes.CallBlock(self.call_method('_get_graph', args), call_args,
                               [], body).set_lineno(lineno)
项目:statik    作者:thanethomson    | 项目源码 | 文件源码
def parse(self, parser):
        lineno = next(parser.stream).lineno

        # get the context
        context = nodes.ContextReference()

        # get the arguments
        args = [context]
        try:
            while True:
                args.append(parser.parse_expression())
        except TemplateSyntaxError:
            pass  # no more arguments

        # get the tag_name for use in looking up callable
        self.active_tag = parser._tag_stack[-1]

        # create the node
        node = self.call_method('_invoke_tag', args=args, lineno=lineno)

        return nodes.Output(
            [node],
            lineno=lineno
        )
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def parse(self, parser):
        return nodes.Output([self.call_method('_dump', [
            nodes.EnvironmentAttribute('sandboxed'),
            self.attr('ext_attr'),
            nodes.ImportedName(__name__ + '.importable_object'),
            nodes.ContextReference()
        ])]).set_lineno(next(parser.stream).lineno)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def parse(self, parser):
        return nodes.Output([self.call_method('_dump', [
            nodes.EnvironmentAttribute('sandboxed'),
            self.attr('ext_attr'),
            nodes.ImportedName(__name__ + '.importable_object'),
            nodes.ContextReference()
        ])]).set_lineno(next(parser.stream).lineno)
项目:pyetje    作者:rorlika    | 项目源码 | 文件源码
def parse(self, parser):
        return nodes.Output([self.call_method('_dump', [
            nodes.EnvironmentAttribute('sandboxed'),
            self.attr('ext_attr'),
            nodes.ImportedName(__name__ + '.importable_object'),
            nodes.ContextReference()
        ])]).set_lineno(next(parser.stream).lineno)
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def parse(self, parser):
        return nodes.Output([self.call_method('_dump', [
            nodes.EnvironmentAttribute('sandboxed'),
            self.attr('ext_attr'),
            nodes.ImportedName(__name__ + '.importable_object'),
            nodes.ContextReference()
        ])]).set_lineno(next(parser.stream).lineno)
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def parse(self, parser):
        return nodes.Output([self.call_method('_dump', [
            nodes.EnvironmentAttribute('sandboxed'),
            self.attr('ext_attr'),
            nodes.ImportedName(__name__ + '.importable_object'),
            nodes.ContextReference()
        ])]).set_lineno(next(parser.stream).lineno)