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

Method __init__

src/jinja2/compiler.py:301–372  ·  view source on GitHub ↗
(
        self,
        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

299
300class CodeGenerator(NodeVisitor):
301 def __init__(
302 self,
303 environment: "Environment",
304 name: t.Optional[str],
305 filename: t.Optional[str],
306 stream: t.Optional[t.TextIO] = None,
307 defer_init: bool = False,
308 optimized: bool = True,
309 ) -> None:
310 if stream is None:
311 stream = StringIO()
312 self.environment = environment
313 self.name = name
314 self.filename = filename
315 self.stream = stream
316 self.created_block_context = False
317 self.defer_init = defer_init
318 self.optimizer: t.Optional[Optimizer] = None
319
320 if optimized:
321 self.optimizer = Optimizer(environment)
322
323 # aliases for imports
324 self.import_aliases: t.Dict[str, str] = {}
325
326 # a registry for all blocks. Because blocks are moved out
327 # into the global python scope they are registered here
328 self.blocks: t.Dict[str, nodes.Block] = {}
329
330 # the number of extends statements so far
331 self.extends_so_far = 0
332
333 # some templates have a rootlevel extends. In this case we
334 # can safely assume that we're a child template and do some
335 # more optimizations.
336 self.has_known_extends = False
337
338 # the current line number
339 self.code_lineno = 1
340
341 # registry of all filters and tests (global, not block local)
342 self.tests: t.Dict[str, str] = {}
343 self.filters: t.Dict[str, str] = {}
344
345 # the debug information
346 self.debug_info: t.List[t.Tuple[int, int]] = []
347 self._write_debug_info: t.Optional[int] = None
348
349 # the number of new lines before the next write()
350 self._new_lines = 0
351
352 # the line number of the last written statement
353 self._last_line = 0
354
355 # true if nothing was written so far.
356 self._first_write = True
357
358 # used by the `temporary_identifier` method to get new

Callers

nothing calls this directly

Calls 1

OptimizerClass · 0.85

Tested by

no test coverage detected