本文整理汇总了Python中jinja2.nodes.CallBlock方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.CallBlock方法的具体用法?Python nodes.CallBlock怎么用?Python nodes.CallBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.nodes
的用法示例。
在下文中一共展示了nodes.CallBlock方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import CallBlock [as 别名]
def parse(self, parser):
lineno = parser.stream.next().lineno
kindarg = parser.parse_expression()
# Allow kind to be defined as jinja2 name node
if isinstance(kindarg, nodes.Name):
kindarg = nodes.Const(kindarg.name)
args = [kindarg]
if args[0].value not in self.compressors:
raise TemplateSyntaxError('compress kind may be one of: %s' %
(', '.join(self.compressors.keys())),
lineno)
if parser.stream.skip_if('comma'):
modearg = parser.parse_expression()
# Allow mode to be defined as jinja2 name node
if isinstance(modearg, nodes.Name):
modearg = nodes.Const(modearg.name)
args.append(modearg)
else:
args.append(nodes.Const('file'))
body = parser.parse_statements(['name:endcompress'], drop_needle=True)
args.append(nodes.Const(unicode(body)))
return nodes.CallBlock(self.call_method('_compress', args), [], [],
body).set_lineno(lineno)
示例2: parse_call_block
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import CallBlock [as 别名]
def parse_call_block(self):
node = nodes.CallBlock(lineno=next(self.stream).lineno)
if self.stream.current.type == 'lparen':
self.parse_signature(node)
else:
node.args = []
node.defaults = []
node.call = self.parse_expression()
if not isinstance(node.call, nodes.Call):
self.fail('expected call', node.lineno)
node.body = self.parse_statements(('name:endcall',), drop_needle=True)
return node
示例3: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import CallBlock [as 别名]
def parse(self, parser):
tag = parser.stream.current.value
lineno = next(parser.stream).lineno
args, kwargs = self.parse_args(parser)
default_cache_key = (None if parser.filename is None
else '%s:%d' % (parser.filename, lineno))
kwargs.append(Keyword('default_cache_key', Const(default_cache_key),
lineno=lineno))
body = parser.parse_statements(['name:end' + tag], drop_needle=True)
return CallBlock(self.call_method('cache', args, kwargs),
[], [], body).set_lineno(lineno)
示例4: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import CallBlock [as 别名]
def parse(self, parser):
lineno = next(parser.stream).lineno
body = parser.parse_statements(
['name:endmarkdown'],
drop_needle=True
)
return CallBlock(
self.call_method('_markdown_support'),
[],
[],
body
).set_lineno(lineno)
示例5: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import CallBlock [as 别名]
def parse(self, parser):
lineno = next(parser.stream).lineno
body = parser.parse_statements(['name:endspaceless'], drop_needle=True)
return nodes.CallBlock(
self.call_method('_strip_spaces', [], [], None, None),
[], [], body,
).set_lineno(lineno)
示例6: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import CallBlock [as 别名]
def parse(self, parser):
lineno = next(parser.stream).lineno # skip past tag token
args = [arg for arg in generate_block_arguments(parser)]
return nodes.CallBlock(
self.call_method('block_callback', args), [], [], []
).set_lineno(lineno)
示例7: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import CallBlock [as 别名]
def parse(self, parser):
lineno = next(parser.stream).lineno
expr = parser.parse_expression()
args = [expr]
kwargs = [nodes.Keyword('func', expr)]
if parser.stream.skip_if('comma'):
# Optional 'note' for function docstring
if (
parser.stream.current.type == 'name' and
parser.stream.current.value in (
'note', 'cond_for', 'depends_on'
)
):
stream_type = parser.stream.current.value
next(parser.stream)
parser.stream.expect('assign')
# Depends meta is always a list
if stream_type == 'depends_on':
c_expr = parser.parse_list()
else:
c_expr = parser.parse_expression()
args.append(c_expr)
kwargs.append(nodes.Keyword(stream_type, c_expr))
body = parser.parse_statements(
['name:endsql', 'name:endquery'], drop_needle=True
)
raw_template = self.environment.sql_params['raws'][parser.name]
# Lines range of original raw template
raw_lines = slice(lineno, parser.stream.current.lineno-1)
self.environment.sql_params.setdefault('funcs', {}).update({
expr.value: {'raw_sql': '\n '.join(raw_template[raw_lines])}
})
call_node = nodes.Call(
self.attr('_sql_process', lineno=lineno),
args, kwargs, None, None
)
return nodes.CallBlock(call_node, [], [], body)