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

Function generate

src/jinja2/compiler.py:101–122  ·  view source on GitHub ↗

Generate the python source for a node tree.

(
    node: nodes.Template,
    environment: "Environment",
    name: t.Optional[str],
    filename: t.Optional[str],
    stream: t.Optional[t.TextIO] = None,
    defer_init: bool = False,
    optimized: bool = True,
)

Source from the content-addressed store, hash-verified

99
100
101def generate(
102 node: nodes.Template,
103 environment: "Environment",
104 name: t.Optional[str],
105 filename: t.Optional[str],
106 stream: t.Optional[t.TextIO] = None,
107 defer_init: bool = False,
108 optimized: bool = True,
109) -> t.Optional[str]:
110 """Generate the python source for a node tree."""
111 if not isinstance(node, nodes.Template):
112 raise TypeError("Can't compile non template nodes")
113
114 generator = environment.code_generator_class(
115 environment, name, filename, stream, defer_init, optimized
116 )
117 generator.visit(node)
118
119 if stream is None:
120 return generator.stream.getvalue() # type: ignore
121
122 return None
123
124
125def has_safe_repr(value: t.Any) -> bool:

Callers 1

_generateMethod · 0.85

Calls 1

visitMethod · 0.80

Tested by

no test coverage detected