Returns line of text with user's change markup and line formatting. lines -- list of lines from the ndiff generator to produce a line of text from. When producing the line of text to return, the lines used are removed from this list. format_key --
(lines, format_key, side, num_lines=[0,0])
| 1401 | diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk) |
| 1402 | |
| 1403 | def _make_line(lines, format_key, side, num_lines=[0,0]): |
| 1404 | """Returns line of text with user's change markup and line formatting. |
| 1405 | |
| 1406 | lines -- list of lines from the ndiff generator to produce a line of |
| 1407 | text from. When producing the line of text to return, the |
| 1408 | lines used are removed from this list. |
| 1409 | format_key -- '+' return first line in list with "add" markup around |
| 1410 | the entire line. |
| 1411 | '-' return first line in list with "delete" markup around |
| 1412 | the entire line. |
| 1413 | '?' return first line in list with add/delete/change |
| 1414 | intraline markup (indices obtained from second line) |
| 1415 | None return first line in list with no markup |
| 1416 | side -- indice into the num_lines list (0=from,1=to) |
| 1417 | num_lines -- from/to current line number. This is NOT intended to be a |
| 1418 | passed parameter. It is present as a keyword argument to |
| 1419 | maintain memory of the current line numbers between calls |
| 1420 | of this function. |
| 1421 | |
| 1422 | Note, this function is purposefully not defined at the module scope so |
| 1423 | that data it needs from its parent function (within whose context it |
| 1424 | is defined) does not need to be of module scope. |
| 1425 | """ |
| 1426 | num_lines[side] += 1 |
| 1427 | # Handle case where no user markup is to be added, just return line of |
| 1428 | # text with user's line format to allow for usage of the line number. |
| 1429 | if format_key is None: |
| 1430 | return (num_lines[side],lines.pop(0)[2:]) |
| 1431 | # Handle case of intraline changes |
| 1432 | if format_key == '?': |
| 1433 | text, markers = lines.pop(0), lines.pop(0) |
| 1434 | # find intraline changes (store change type and indices in tuples) |
| 1435 | sub_info = [] |
| 1436 | def record_sub_info(match_object,sub_info=sub_info): |
| 1437 | sub_info.append([match_object.group(1)[0],match_object.span()]) |
| 1438 | return match_object.group(1) |
| 1439 | change_re.sub(record_sub_info,markers) |
| 1440 | # process each tuple inserting our special marks that won't be |
| 1441 | # noticed by an xml/html escaper. |
| 1442 | for key,(begin,end) in reversed(sub_info): |
| 1443 | text = text[0:begin]+'\0'+key+text[begin:end]+'\1'+text[end:] |
| 1444 | text = text[2:] |
| 1445 | # Handle case of add/delete entire line |
| 1446 | else: |
| 1447 | text = lines.pop(0)[2:] |
| 1448 | # if line of text is just a newline, insert a space so there is |
| 1449 | # something for the user to highlight and see. |
| 1450 | if not text: |
| 1451 | text = ' ' |
| 1452 | # insert marks that won't be noticed by an xml/html escaper. |
| 1453 | text = '\0' + format_key + text + '\1' |
| 1454 | # Return line of text, first allow user's line formatter to do its |
| 1455 | # thing (such as adding the line number) then replace the special |
| 1456 | # marks with what the user's change markup. |
| 1457 | return (num_lines[side],text) |
| 1458 | |
| 1459 | def _line_iterator(): |
| 1460 | """Yields from/to lines of text with a change indication. |
no test coverage detected
searching dependent graphs…