Generate this template with the given arguments.
(self, **kwargs: Any)
| 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() |