| 283 | |
| 284 | |
| 285 | def remove_unindented_lines(code, protect_before, execeptions, trim_tails): |
| 286 | lines = code.splitlines() |
| 287 | cut_idx = [] |
| 288 | cut_enabled = False |
| 289 | for i, line in enumerate(lines): |
| 290 | if not cut_enabled and line.startswith(protect_before): |
| 291 | cut_enabled = True |
| 292 | continue |
| 293 | if line.strip() == "": |
| 294 | continue |
| 295 | if any(line.startswith(e) for e in execeptions): |
| 296 | continue |
| 297 | |
| 298 | lspace = len(line) - len(line.lstrip()) |
| 299 | if lspace == 0: |
| 300 | cut_idx.append(i) |
| 301 | |
| 302 | if any(line.rstrip().startswith(t) for t in trim_tails): |
| 303 | # cut off everything behind |
| 304 | cut_idx.extend(list(range(i, len(lines)))) |
| 305 | break |
| 306 | |
| 307 | return "\n".join([line for i, line in enumerate(lines) if i not in cut_idx]) |
| 308 | |
| 309 | |
| 310 | def to_four_space_indents(old_code): |