Yields from/to lines of text with a change indication. This function is an iterator. It itself pulls lines from the line iterator. Its difference from that iterator is that this function always yields a pair of from/to text lines (with the change indication).
()
| 1524 | yield from_line,to_line,True |
| 1525 | |
| 1526 | def _line_pair_iterator(): |
| 1527 | """Yields from/to lines of text with a change indication. |
| 1528 | |
| 1529 | This function is an iterator. It itself pulls lines from the line |
| 1530 | iterator. Its difference from that iterator is that this function |
| 1531 | always yields a pair of from/to text lines (with the change |
| 1532 | indication). If necessary it will collect single from/to lines |
| 1533 | until it has a matching pair from/to pair to yield. |
| 1534 | |
| 1535 | Note, this function is purposefully not defined at the module scope so |
| 1536 | that data it needs from its parent function (within whose context it |
| 1537 | is defined) does not need to be of module scope. |
| 1538 | """ |
| 1539 | line_iterator = _line_iterator() |
| 1540 | fromlines,tolines=[],[] |
| 1541 | while True: |
| 1542 | # Collecting lines of text until we have a from/to pair |
| 1543 | while (len(fromlines)==0 or len(tolines)==0): |
| 1544 | try: |
| 1545 | from_line, to_line, found_diff = next(line_iterator) |
| 1546 | except StopIteration: |
| 1547 | return |
| 1548 | if from_line is not None: |
| 1549 | fromlines.append((from_line,found_diff)) |
| 1550 | if to_line is not None: |
| 1551 | tolines.append((to_line,found_diff)) |
| 1552 | # Once we have a pair, remove them from the collection and yield it |
| 1553 | from_line, fromDiff = fromlines.pop(0) |
| 1554 | to_line, to_diff = tolines.pop(0) |
| 1555 | yield (from_line,to_line,fromDiff or to_diff) |
| 1556 | |
| 1557 | # Handle case where user does not want context differencing, just yield |
| 1558 | # them up without doing anything else with them. |
no test coverage detected