| 21 | |
| 22 | |
| 23 | def remove_unindented_lines( |
| 24 | code: str, protect_before: str, execeptions: List[str], trim_tails: List[str] |
| 25 | ) -> str: |
| 26 | lines = code.splitlines() |
| 27 | cut_idx = [] |
| 28 | cut_enabled = False |
| 29 | for i, line in enumerate(lines): |
| 30 | if not cut_enabled and line.startswith(protect_before): |
| 31 | cut_enabled = True |
| 32 | continue |
| 33 | if line.strip() == "": |
| 34 | continue |
| 35 | if any(line.startswith(e) for e in execeptions): |
| 36 | continue |
| 37 | |
| 38 | lspace = len(line) - len(line.lstrip()) |
| 39 | if lspace == 0: |
| 40 | cut_idx.append(i) |
| 41 | |
| 42 | if any(line.rstrip().startswith(t) for t in trim_tails): |
| 43 | # cut off everything behind |
| 44 | cut_idx.extend(list(range(i, len(lines)))) |
| 45 | break |
| 46 | |
| 47 | return "\n".join([line for i, line in enumerate(lines) if i not in cut_idx]) |
| 48 | |
| 49 | |
| 50 | def to_four_space_indents(old_code): |