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
(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK)
| 1301 | yield line.encode('ascii', 'surrogateescape') |
| 1302 | |
| 1303 | def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK): |
| 1304 | r""" |
| 1305 | Compare `a` and `b` (lists of strings); return a `Differ`-style delta. |
| 1306 | |
| 1307 | Optional keyword parameters `linejunk` and `charjunk` are for filter |
| 1308 | functions, or can be None: |
| 1309 | |
| 1310 | - linejunk: A function that should accept a single string argument and |
| 1311 | return true iff the string is junk. The default is None, and is |
| 1312 | recommended; the underlying SequenceMatcher class has an adaptive |
| 1313 | notion of "noise" lines. |
| 1314 | |
| 1315 | - charjunk: A function that accepts a character (string of length |
| 1316 | 1), and returns true iff the character is junk. The default is |
| 1317 | the module-level function IS_CHARACTER_JUNK, which filters out |
| 1318 | whitespace characters (a blank or tab; note: it's a bad idea to |
| 1319 | include newline in this!). |
| 1320 | |
| 1321 | Tools/scripts/ndiff.py is a command-line front-end to this function. |
| 1322 | |
| 1323 | Example: |
| 1324 | |
| 1325 | >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(keepends=True), |
| 1326 | ... 'ore\ntree\nemu\n'.splitlines(keepends=True)) |
| 1327 | >>> print(''.join(diff), end="") |
| 1328 | - one |
| 1329 | ? ^ |
| 1330 | + ore |
| 1331 | ? ^ |
| 1332 | - two |
| 1333 | - three |
| 1334 | ? - |
| 1335 | + tree |
| 1336 | + emu |
| 1337 | """ |
| 1338 | return Differ(linejunk, charjunk).compare(a, b) |
| 1339 | |
| 1340 | def _mdiff(fromlines, tolines, context=None, linejunk=None, |
| 1341 | charjunk=IS_CHARACTER_JUNK): |