Remove leading indentation. If the first line starts with a spaces or tabs, the same whitespace will be removed from each following line until it is reset.
()
| 474 | |
| 475 | @CoroutineInputTransformer.wrap |
| 476 | def leading_indent(): |
| 477 | """Remove leading indentation. |
| 478 | |
| 479 | If the first line starts with a spaces or tabs, the same whitespace will be |
| 480 | removed from each following line until it is reset. |
| 481 | """ |
| 482 | space_re = re.compile(r'^[ \t]+') |
| 483 | line = '' |
| 484 | while True: |
| 485 | line = (yield line) |
| 486 | |
| 487 | if line is None: |
| 488 | continue |
| 489 | |
| 490 | m = space_re.match(line) |
| 491 | if m: |
| 492 | space = m.group(0) |
| 493 | while line is not None: |
| 494 | if line.startswith(space): |
| 495 | line = line[len(space):] |
| 496 | line = (yield line) |
| 497 | else: |
| 498 | # No leading spaces - wait for reset |
| 499 | while line is not None: |
| 500 | line = (yield line) |
| 501 | |
| 502 | |
| 503 | _assign_pat = \ |