diff options
author | Raymond Hettinger <python@rcn.com> | 2003-06-08 19:38:42 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-06-08 19:38:42 (GMT) |
commit | 7f2d302a1611fff03fc986a9b5c369feb7fbab1d (patch) | |
tree | 6a21945777590f77e34e55f1db7ba8b786c9aa2b /Lib | |
parent | 305908cffdc82956826d85571119dbf031ce0c04 (diff) | |
download | cpython-7f2d302a1611fff03fc986a9b5c369feb7fbab1d.zip cpython-7f2d302a1611fff03fc986a9b5c369feb7fbab1d.tar.gz cpython-7f2d302a1611fff03fc986a9b5c369feb7fbab1d.tar.bz2 |
For the context and unified diff functions:
* Simplified test for visible changes
* Improved variable names and line spacing
* Replaced dict(a=3) style with Py2.2 compatable {'a':3}
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/difflib.py | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py index 202b815..da3d79b 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -1205,38 +1205,32 @@ def context_diff(a, b, fromfile='', tofile='', """ started = False - prefixmap = dict(insert='+ ', delete='- ', replace='! ', equal=' ') + prefixmap = {'insert':'+ ', 'delete':'- ', 'replace':'! ', 'equal':' '} for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n): if not started: yield '*** %s %s%s' % (fromfile, fromfiledate, lineterm) yield '--- %s %s%s' % (tofile, tofiledate, lineterm) started = True + yield '***************%s' % (lineterm,) if group[-1][2] - group[0][1] >= 2: yield '*** %d,%d ****%s' % (group[0][1]+1, group[-1][2], lineterm) else: yield '*** %d ****%s' % (group[-1][2], lineterm) - empty = True - for tag, i1, i2, j1, j2 in group: - if tag == 'replace' or tag == 'delete': - empty = False - break - if not empty: - for tag, i1, i2, j1, j2 in group: + visiblechanges = [e for e in group if e[0] in ('replace', 'delete')] + if visiblechanges: + for tag, i1, i2, _, _ in group: if tag != 'insert': for line in a[i1:i2]: yield prefixmap[tag] + line + if group[-1][4] - group[0][3] >= 2: yield '--- %d,%d ----%s' % (group[0][3]+1, group[-1][4], lineterm) else: yield '--- %d ----%s' % (group[-1][4], lineterm) - empty = True - for tag, i1, i2, j1, j2 in group: - if tag == 'replace' or tag == 'insert': - empty = False - break - if not empty: - for tag, i1, i2, j1, j2 in group: + visiblechanges = [e for e in group if e[0] in ('replace', 'insert')] + if visiblechanges: + for tag, _, _, j1, j2 in group: if tag != 'delete': for line in b[j1:j2]: yield prefixmap[tag] + line |