| 592 | |
| 593 | |
| 594 | class _ApplyBlock(_Node): |
| 595 | def __init__(self, method: str, line: int, body: _Node) -> None: |
| 596 | self.method = method |
| 597 | self.line = line |
| 598 | self.body = body |
| 599 | |
| 600 | def each_child(self) -> Iterable["_Node"]: |
| 601 | return (self.body,) |
| 602 | |
| 603 | def generate(self, writer: "_CodeWriter") -> None: |
| 604 | method_name = "_tt_apply%d" % writer.apply_counter |
| 605 | writer.apply_counter += 1 |
| 606 | writer.write_line("def %s():" % method_name, self.line) |
| 607 | with writer.indent(): |
| 608 | writer.write_line("_tt_buffer = []", self.line) |
| 609 | writer.write_line("_tt_append = _tt_buffer.append", self.line) |
| 610 | self.body.generate(writer) |
| 611 | writer.write_line("return _tt_utf8('').join(_tt_buffer)", self.line) |
| 612 | writer.write_line( |
| 613 | "_tt_append(_tt_utf8(%s(%s())))" % (self.method, method_name), self.line |
| 614 | ) |
| 615 | |
| 616 | |
| 617 | class _ControlBlock(_Node): |