def context_diff(a, b, fromfile='<STR_LIT>', tofile='<STR_LIT>',<EOL>fromfiledate='<STR_LIT>', tofiledate='<STR_LIT>', n=<NUM_LIT:3>, lineterm='<STR_LIT:\n>'):
prefix = dict(insert='<STR_LIT>', delete='<STR_LIT>', replace='<STR_LIT>', equal='<STR_LIT:U+0020>')<EOL>started = False<EOL>for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):<EOL><INDENT>if not started:<EOL><INDENT>started = True<EOL>fromdate = '<STR_LIT>' % (fromfiledate) if fromfiledate else '<STR_LIT>'<EOL>todate = '<STR_LIT>' % (tofiledate) if tofiledate else '<STR_LIT>'<EOL>yield '<STR_LIT>' % (fromfile, fromdate, lineterm)<EOL>yield '<STR_LIT>' % (tofile, todate, lineterm)<EOL><DEDENT>first, last = group[<NUM_LIT:0>], group[-<NUM_LIT:1>]<EOL>yield '<STR_LIT>' + lineterm<EOL>file1_range = _format_range_context(first[<NUM_LIT:1>], last[<NUM_LIT:2>])<EOL>yield '<STR_LIT>' % (file1_range, lineterm)<EOL>if any(tag in ('<STR_LIT:replace>', '<STR_LIT>') for tag, _, _, _, _ in group):<EOL><INDENT>for tag, i1, i2, _, _ in group:<EOL><INDENT>if tag != '<STR_LIT>':<EOL><INDENT>for line in a[i1:i2]:<EOL><INDENT>yield prefix[tag] + line<EOL><DEDENT><DEDENT><DEDENT><DEDENT>file2_range = _format_range_context(first[<NUM_LIT:3>], last[<NUM_LIT:4>])<EOL>yield '<STR_LIT>' % (file2_range, lineterm)<EOL>if any(tag in ('<STR_LIT:replace>', '<STR_LIT>') for tag, _, _, _, _ in group):<EOL><INDENT>for tag, _, _, j1, j2 in group:<EOL><INDENT>if tag != '<STR_LIT>':<EOL><INDENT>for line in b[j1:j2]:<EOL><INDENT>yield prefix[tag] + line<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
r"""
    Compare two sequences of lines; generate the delta as a context diff.

    Context diffs are a compact way of showing line changes and a few
    lines of context.  The number of context lines is set by 'n' which
    defaults to three.

    By default, the diff control lines (those with *** or ---) are
    created with a trailing newline.  This is helpful so that inputs
    created from file.readlines() result in diffs that are suitable for
    file.writelines() since both the inputs and outputs have trailing
    newlines.

    For inputs that do not have trailing newlines, set the lineterm
    argument to "" so that the output will be uniformly newline free.

    The context diff format normally has a header for filenames and
    modification times.  Any or all of these may be specified using
    strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
    The modification times are normally expressed in the ISO 8601 format.
    If not specified, the strings default to blanks.

    Example:

    >>> print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1),
    ...       'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current')),
    *** Original
    --- Current
    ***************
    *** 1,4 ****
      one
    ! two
    ! three
      four
    --- 1,4 ----
    + zero
      one
    ! tree
      four