本文整理匯總了Python中jinja2.nodes.Slice方法的典型用法代碼示例。如果您正苦於以下問題:Python nodes.Slice方法的具體用法?Python nodes.Slice怎麽用?Python nodes.Slice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jinja2.nodes
的用法示例。
在下文中一共展示了nodes.Slice方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: visit_Getitem
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Slice [as 別名]
def visit_Getitem(self, node, frame):
# slices bypass the environment getitem method.
if isinstance(node.arg, nodes.Slice):
self.visit(node.node, frame)
self.write('[')
self.visit(node.arg, frame)
self.write(']')
else:
self.write('environment.getitem(')
self.visit(node.node, frame)
self.write(', ')
self.visit(node.arg, frame)
self.write(')')
示例2: parse_subscribed
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Slice [as 別名]
def parse_subscribed(self):
lineno = self.stream.current.lineno
if self.stream.current.type == 'colon':
next(self.stream)
args = [None]
else:
node = self.parse_expression()
if self.stream.current.type != 'colon':
return node
next(self.stream)
args = [node]
if self.stream.current.type == 'colon':
args.append(None)
elif self.stream.current.type not in ('rbracket', 'comma'):
args.append(self.parse_expression())
else:
args.append(None)
if self.stream.current.type == 'colon':
next(self.stream)
if self.stream.current.type not in ('rbracket', 'comma'):
args.append(self.parse_expression())
else:
args.append(None)
else:
args.append(None)
return nodes.Slice(lineno=lineno, *args)
示例3: _process_getitem
# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Slice [as 別名]
def _process_getitem(self, node, **kwargs):
"""
Processes a `GetItem` node e.g. {{ foo["bar"] }}
"""
with self._interpolation():
with self._python_bool_wrapper(**kwargs) as new_kwargs:
self._process_node(node.node, **new_kwargs)
if isinstance(node.arg, nodes.Slice):
self.output.write('.slice(')
if node.arg.step is not None:
raise Exception('The step argument is not supported when slicing.')
if node.arg.start is None:
self.output.write('0')
else:
self._process_node(node.arg.start, **new_kwargs)
if node.arg.stop is None:
self.output.write(')')
else:
self.output.write(',')
self._process_node(node.arg.stop, **new_kwargs)
self.output.write(')')
else:
self.output.write('[')
self._process_node(node.arg, **new_kwargs)
self.output.write(']')