本文整理汇总了Python中jinja2.nodes.Output方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.Output方法的具体用法?Python nodes.Output怎么用?Python nodes.Output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.nodes
的用法示例。
在下文中一共展示了nodes.Output方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def parse(self, parser):
stream = parser.stream
tag = stream.next()
# get arguments
args = []
kwargs = []
while not stream.current.test_any('block_end'):
if args or kwargs:
stream.expect('comma')
if stream.current.test('name') and stream.look().test('assign'):
key = nodes.Const(stream.next().value)
stream.skip()
value = parser.parse_expression()
kwargs.append(nodes.Pair(key, value, lineno=key.lineno))
else:
args.append(parser.parse_expression())
def make_call_node(*kw):
return self.call_method('_call', args=[
nodes.List(args),
nodes.Dict(kwargs),
], kwargs=kw)
return nodes.Output([make_call_node()]).set_lineno(tag.lineno)
示例2: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def parse(self, parser):
def parse_arguments():
args = [parser.parse_expression()]
# append task filters if any
if parser.stream.skip_if('comma'):
args.append(parser.parse_expression())
return args
lineno = next(parser.stream).lineno
tag_args = parse_arguments()
call = self.call_method(self._include_tasks.__name__, tag_args)
return Output([call], lineno=lineno)
# By default, `yaml` package does not preserve field order, and
# playbook tasks do not look the same as in playbooks and in docs.
# These functions create custom Loader and Dumper to preserve field order.
# Source: https://stackoverflow.com/a/21912744
示例3: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def parse(self, parser):
lineno = next(parser.stream).lineno
# get the first parameter: the view name
args = [parser.parse_expression()]
# if there's a comma, we've also got an instance variable here
if parser.stream.skip_if('comma'):
args.append(parser.parse_expression())
else:
# no instance supplied for URL tag
args.append(nodes.Const(None))
return nodes.Output(
[self.call_method('_url', args)],
lineno=lineno
)
示例4: parse_print
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def parse_print(self):
node = nodes.Output(lineno=next(self.stream).lineno)
node.nodes = []
while self.stream.current.type != 'block_end':
if node.nodes:
self.stream.expect('comma')
node.nodes.append(self.parse_expression())
return node
示例5: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def parse(self, parser):
lineno = parser.stream.expect('name:csrf_token').lineno
call = self.call_method(
'_csrf_token',
[nodes.Name('csrf_token', 'load', lineno=lineno)],
lineno=lineno
)
return nodes.Output([nodes.MarkSafe(call)])
示例6: _parse_trans
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def _parse_trans(self, parser, lineno):
string = parser.stream.expect(lexer.TOKEN_STRING)
string = nodes.Const(string.value, lineno=string.lineno)
is_noop = False
context = None
as_var = None
for token in iter(lambda: parser.stream.next_if(lexer.TOKEN_NAME), None):
if token.value == 'noop' and not is_noop:
if context is not None:
parser.fail("noop translation can't have context", lineno=token.lineno)
is_noop = True
elif token.value == 'context' and context is None:
if is_noop:
parser.fail("noop translation can't have context", lineno=token.lineno)
context = parser.stream.expect(lexer.TOKEN_STRING)
context = nodes.Const(context.value, lineno=context.lineno)
elif token.value == 'as' and as_var is None:
as_var = parser.stream.expect(lexer.TOKEN_NAME)
as_var = nodes.Name(as_var.value, 'store', lineno=as_var.lineno)
else:
parser.fail("expected 'noop', 'context' or 'as'", lineno=token.lineno)
if is_noop:
output = string
elif context is not None:
func = nodes.Name('pgettext', 'load', lineno=lineno)
output = nodes.Call(func, [context, string], [], None, None, lineno=lineno)
else:
func = nodes.Name('gettext', 'load')
output = nodes.Call(func, [string], [], None, None, lineno=lineno)
if as_var is None:
return nodes.Output([output], lineno=lineno)
else:
return nodes.Assign(as_var, output, lineno=lineno)
示例7: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def parse(self, parser):
list_of_paths = getattr(settings, 'LATEX_GRAPHICSPATH', [settings.BASE_DIR])
value = '\graphicspath{ ' + ' '.join(map(format_path_for_latex, list_of_paths)) + ' }'
node = nodes.Output(lineno=next(parser.stream).lineno)
node.nodes = [nodes.MarkSafe(nodes.Const(value))]
return node
示例8: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
def parse(self, parser):
lineno = next(parser.stream).lineno
node = parser.parse_expression()
if parser.stream.skip_if('comma'):
datetime_format = parser.parse_expression()
else:
datetime_format = nodes.Const(None)
if isinstance(node, nodes.Add):
call_method = self.call_method(
'_datetime',
[node.left, nodes.Const('+'), node.right, datetime_format],
lineno=lineno,
)
elif isinstance(node, nodes.Sub):
call_method = self.call_method(
'_datetime',
[node.left, nodes.Const('-'), node.right, datetime_format],
lineno=lineno,
)
else:
call_method = self.call_method(
'_now',
[node, datetime_format],
lineno=lineno,
)
return nodes.Output([call_method], lineno=lineno)
示例9: parse
# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Output [as 别名]
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)