MCPcopy
hub / github.com/pallets/jinja / parse_from

Method parse_from

src/jinja2/parser.py:364–404  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

362 return self.parse_import_context(node, False)
363
364 def parse_from(self) -> nodes.FromImport:
365 node = nodes.FromImport(lineno=next(self.stream).lineno)
366 node.template = self.parse_expression()
367 self.stream.expect("name:import")
368 node.names = []
369
370 def parse_context() -> bool:
371 if self.stream.current.value in {
372 "with",
373 "without",
374 } and self.stream.look().test("name:context"):
375 node.with_context = next(self.stream).value == "with"
376 self.stream.skip()
377 return True
378 return False
379
380 while True:
381 if node.names:
382 self.stream.expect("comma")
383 if self.stream.current.type == "name":
384 if parse_context():
385 break
386 target = self.parse_assign_target(name_only=True)
387 if target.name.startswith("_"):
388 self.fail(
389 "names starting with an underline can not be imported",
390 target.lineno,
391 exc=TemplateAssertionError,
392 )
393 if self.stream.skip_if("name:as"):
394 alias = self.parse_assign_target(name_only=True)
395 node.names.append((target.name, alias.name))
396 else:
397 node.names.append(target.name)
398 if parse_context() or self.stream.current.type != "comma":
399 break
400 else:
401 self.stream.expect("name")
402 if not hasattr(node, "with_context"):
403 node.with_context = False
404 return node
405
406 def parse_signature(self, node: _MacroCall) -> None:
407 args = node.args = []

Callers

nothing calls this directly

Calls 5

parse_expressionMethod · 0.95
parse_assign_targetMethod · 0.95
failMethod · 0.95
expectMethod · 0.80
skip_ifMethod · 0.80

Tested by

no test coverage detected