| 36 | |
| 37 | |
| 38 | class AligningWalker(SourceWalker, object): |
| 39 | def __init__( |
| 40 | self, |
| 41 | version, |
| 42 | out, |
| 43 | scanner, |
| 44 | showast=TREE_DEFAULT_DEBUG, |
| 45 | debug_parser=PARSER_DEFAULT_DEBUG, |
| 46 | compile_mode="exec", |
| 47 | is_pypy=False, |
| 48 | ): |
| 49 | SourceWalker.__init__( |
| 50 | self, version, out, scanner, showast, debug_parser, compile_mode, is_pypy |
| 51 | ) |
| 52 | self.desired_line_number = 0 |
| 53 | self.current_line_number = 0 |
| 54 | self.showast = showast |
| 55 | |
| 56 | def println(self, *data): |
| 57 | if data and not (len(data) == 1 and data[0] == ""): |
| 58 | self.write(*data) |
| 59 | |
| 60 | self.pending_newlines = max(self.pending_newlines, 1) |
| 61 | |
| 62 | def write(self, *data): |
| 63 | if (len(data) == 1) and data[0] == self.indent: |
| 64 | diff = max( |
| 65 | self.pending_newlines, |
| 66 | self.desired_line_number - self.current_line_number, |
| 67 | ) |
| 68 | self.f.write("\n" * diff) |
| 69 | self.current_line_number += diff |
| 70 | self.pending_newlines = 0 |
| 71 | if (len(data) == 0) or (len(data) == 1 and data[0] == ""): |
| 72 | return |
| 73 | |
| 74 | out = "".join((str(j) for j in data)) |
| 75 | n = 0 |
| 76 | for i in out: |
| 77 | if i == "\n": |
| 78 | n += 1 |
| 79 | if n == len(out): |
| 80 | self.pending_newlines = max(self.pending_newlines, n) |
| 81 | return |
| 82 | elif n: |
| 83 | self.pending_newlines = max(self.pending_newlines, n) |
| 84 | out = out[n:] |
| 85 | break |
| 86 | else: |
| 87 | break |
| 88 | |
| 89 | if self.pending_newlines > 0: |
| 90 | diff = max( |
| 91 | self.pending_newlines, |
| 92 | self.desired_line_number - self.current_line_number, |
| 93 | ) |
| 94 | self.f.write("\n" * diff) |
| 95 | self.current_line_number += diff |
no outgoing calls
no test coverage detected