Returns information about the current line and surrounding lines.
(line, next_line, previous_line)
| 508 | |
| 509 | |
| 510 | def _create_line_info(line, next_line, previous_line): |
| 511 | """Returns information about the current line and surrounding lines.""" |
| 512 | line_info = Namespace() # TODO(dbieber): Switch to an explicit class. |
| 513 | line_info.line = line |
| 514 | line_info.stripped = line.strip() |
| 515 | line_info.remaining_raw = line_info.line |
| 516 | line_info.remaining = line_info.stripped |
| 517 | line_info.indentation = len(line) - len(line.lstrip()) |
| 518 | # TODO(dbieber): If next_line is blank, use the next non-blank line. |
| 519 | line_info.next.line = next_line |
| 520 | next_line_exists = next_line is not None |
| 521 | line_info.next.stripped = next_line.strip() if next_line_exists else None |
| 522 | line_info.next.indentation = ( |
| 523 | len(next_line) - len(next_line.lstrip()) if next_line_exists else None) |
| 524 | line_info.previous.line = previous_line |
| 525 | previous_line_exists = previous_line is not None |
| 526 | line_info.previous.indentation = ( |
| 527 | len(previous_line) - |
| 528 | len(previous_line.lstrip()) if previous_line_exists else None) |
| 529 | # Note: This counts all whitespace equally. |
| 530 | return line_info |
| 531 | |
| 532 | |
| 533 | def _update_section_state(line_info, state): |