8 DIFF_RE = re.compile(r"""\x00([+^-])""" ,re.UNICODE)
9 NAMES = { '+': 'added', '-': 'removed', '^': 'changed' }
11 def diff_replace(match):
12 return """<span class="diff_mark diff_mark_%s">""" % NAMES[match.group(1)]
15 def filter_line(line):
16 return DIFF_RE.sub(diff_replace, line).replace('\x01', '</span>')
22 a, b, _ = diffs.next()
28 a, b, _ = diffs.next()
33 a, b, _ = diffs.next()
37 yield group_a[:-1], group_b[:-1]
38 group_a, group_b = group_a[-1:], group_b[-1:]
40 def join_to_html(diffs):
41 for group_a, group_b in group(diffs):
43 <div class="change_block">
44 <div class="old_block">%s</div>
45 <div class="new_block">%s</div>
47 '\n'.join( filter_line(line) for line in group_a ),
48 '\n'.join( filter_line(line) for line in group_b ),
51 fa = read_whole("file_a")
52 fb = read_whole("file_b")
54 print '\n'.join( repr(x) for x in difflib._mdiff(fa, fb) )
55 print "**************************"
56 print '\n'.join( join_to_html( difflib._mdiff(fa, fb) ) )
57 # print '\n'.join( repr(x) for x in group(difflib._mdiff(fa, fb)) )