r""" Compare `a` and `b` (lists of strings); return a `Differ`-style delta. Optional keyword parameters `linejunk` and `charjunk` are for filter functions, or can be None: - linejunk: A function that should accept a single string argument and return true iff the string is jun
(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK)
| 1322 | yield line.encode('ascii', 'surrogateescape') |
| 1323 | |
| 1324 | def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): |
| 1325 | r""" |
| 1326 | Compare `a` and `b` (lists of strings); return a `Differ`-style delta. |
| 1327 | |
| 1328 | Optional keyword parameters `linejunk` and `charjunk` are for filter |
| 1329 | functions, or can be None: |
| 1330 | |
| 1331 | - linejunk: A function that should accept a single string argument and |
| 1332 | return true iff the string is junk. The default is None, and is |
| 1333 | recommended; the underlying SequenceMatcher class has an adaptive |
| 1334 | notion of "noise" lines. |
| 1335 | |
| 1336 | - charjunk: A function that accepts a character (string of length |
| 1337 | 1), and returns true iff the character is junk. The default is |
| 1338 | the module-level function IS_CHARACTER_JUNK, which filters out |
| 1339 | whitespace characters (a blank or tab; note: it's a bad idea to |
| 1340 | include newline in this!). |
| 1341 | |
| 1342 | Tools/scripts/ndiff.py is a command-line front-end to this function. |
| 1343 | |
| 1344 | Example: |
| 1345 | |
| 1346 | >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), |
| 1347 | ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) |
| 1348 | >>> print(''.join(diff), end="") |
| 1349 | - one |
| 1350 | ? ^ |
| 1351 | + ore |
| 1352 | ? ^ |
| 1353 | - two |
| 1354 | - three |
| 1355 | ? - |
| 1356 | + tree |
| 1357 | + emu |
| 1358 | """ |
| 1359 | return Differ(linejunk, charjunk).compare(a, b) |
| 1360 | |
| 1361 | def _mdiff(fromlines, tolines, context=None, linejunk=None, |
| 1362 | charjunk=IS_CHARACTER_JUNK): |