r"""Returns generator yielding marked up from/to side by side differences. Arguments: fromlines -- list of text lines to compared to tolines tolines -- list of text lines to be compared to fromlines context -- number of context lines to display on each side of difference,
(fromlines, tolines, context=None, linejunk=None,
charjunk=IS_CHARACTER_JUNK)
| 1359 | return Differ(linejunk, charjunk).compare(a, b) |
| 1360 | |
| 1361 | def _mdiff(fromlines, tolines, context=None, linejunk=None, |
| 1362 | charjunk=IS_CHARACTER_JUNK): |
| 1363 | r"""Returns generator yielding marked up from/to side by side differences. |
| 1364 | |
| 1365 | Arguments: |
| 1366 | fromlines -- list of text lines to compared to tolines |
| 1367 | tolines -- list of text lines to be compared to fromlines |
| 1368 | context -- number of context lines to display on each side of difference, |
| 1369 | if None, all from/to text lines will be generated. |
| 1370 | linejunk -- passed on to ndiff (see ndiff documentation) |
| 1371 | charjunk -- passed on to ndiff (see ndiff documentation) |
| 1372 | |
| 1373 | This function returns an iterator which returns a tuple: |
| 1374 | (from line tuple, to line tuple, boolean flag) |
| 1375 | |
| 1376 | from/to line tuple -- (line num, line text) |
| 1377 | line num -- integer or None (to indicate a context separation) |
| 1378 | line text -- original line text with following markers inserted: |
| 1379 | '\0+' -- marks start of added text |
| 1380 | '\0-' -- marks start of deleted text |
| 1381 | '\0^' -- marks start of changed text |
| 1382 | '\1' -- marks end of added/deleted/changed text |
| 1383 | |
| 1384 | boolean flag -- None indicates context separation, True indicates |
| 1385 | either "from" or "to" line contains a change, otherwise False. |
| 1386 | |
| 1387 | This function/iterator was originally developed to generate side by side |
| 1388 | file difference for making HTML pages (see HtmlDiff class for example |
| 1389 | usage). |
| 1390 | |
| 1391 | Note, this function utilizes the ndiff function to generate the side by |
| 1392 | side difference markup. Optional ndiff arguments may be passed to this |
| 1393 | function and they in turn will be passed to ndiff. |
| 1394 | """ |
| 1395 | import re |
| 1396 | |
| 1397 | # regular expression for finding intraline change indices |
| 1398 | change_re = re.compile(r'(\++|\-+|\^+)') |
| 1399 | |
| 1400 | # create the difference iterator to generate the differences |
| 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 |
no test coverage detected
searching dependent graphs…