MCPcopy
hub / github.com/tornadoweb/tornado / generate

Method generate

tornado/template.py:337–362  ·  view source on GitHub ↗

Generate this template with the given arguments.

(self, **kwargs: Any)

Source from the content-addressed store, hash-verified

335 raise
336
337 def generate(self, **kwargs: Any) -> bytes:
338 """Generate this template with the given arguments."""
339 namespace = {
340 "escape": escape.xhtml_escape,
341 "xhtml_escape": escape.xhtml_escape,
342 "url_escape": escape.url_escape,
343 "json_encode": escape.json_encode,
344 "squeeze": escape.squeeze,
345 "linkify": escape.linkify,
346 "datetime": datetime,
347 "_tt_utf8": escape.utf8, # for internal use
348 "_tt_string_types": (unicode_type, bytes),
349 # __name__ and __loader__ allow the traceback mechanism to find
350 # the generated source code.
351 "__name__": self.name.replace(".", "_"),
352 "__loader__": ObjectDict(get_source=lambda name: self.code),
353 }
354 namespace.update(self.namespace)
355 namespace.update(kwargs)
356 exec_in(self.compiled, namespace)
357 execute = typing.cast(Callable[[], bytes], namespace["_tt_execute"])
358 # Clear the traceback module's cache of source data now that
359 # we've generated a new template (mainly for this module's
360 # unittests, where different tests reuse the same name).
361 linecache.clearcache()
362 return execute()
363
364 def _generate_python(self, loader: Optional["BaseLoader"]) -> str:
365 buffer = StringIO()

Callers 15

test_simpleMethod · 0.95
test_bytesMethod · 0.95
test_expressionsMethod · 0.95
test_commentMethod · 0.95
test_unicode_templateMethod · 0.95
test_applyMethod · 0.95
test_unicode_applyMethod · 0.95
test_bytes_applyMethod · 0.95
test_ifMethod · 0.95
test_if_empty_bodyMethod · 0.95
test_tryMethod · 0.95

Calls 3

ObjectDictClass · 0.90
exec_inFunction · 0.90
replaceMethod · 0.80

Tested by 15

test_simpleMethod · 0.76
test_bytesMethod · 0.76
test_expressionsMethod · 0.76
test_commentMethod · 0.76
test_unicode_templateMethod · 0.76
test_applyMethod · 0.76
test_unicode_applyMethod · 0.76
test_bytes_applyMethod · 0.76
test_ifMethod · 0.76
test_if_empty_bodyMethod · 0.76
test_tryMethod · 0.76