Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.support.difflib Namespace Reference

Classes

class  SequenceMatcher
class  Differ
class  HtmlDiff

Functions

def _calculate_ratio
def get_close_matches
def _count_leading
def IS_LINE_JUNK
def IS_CHARACTER_JUNK
def unified_diff
def context_diff
def ndiff
def _mdiff
def restore
def _test

Variables

list __all__
string _file_template
string _styles
string _table_template
string _legend

Function Documentation

def MoinMoin.support.difflib._calculate_ratio (   matches,
  length 
) [private]

Definition at line 40 of file difflib.py.

00040 
00041 def _calculate_ratio(matches, length):
00042     if length:
00043         return 2.0 * matches / length
00044     return 1.0

Here is the caller graph for this function:

def MoinMoin.support.difflib._count_leading (   line,
  ch 
) [private]
Return number of `ch` characters at the start of `line`.

Example:

>>> _count_leading('   abc', ' ')
3

Definition at line 755 of file difflib.py.

00755 
00756 def _count_leading(line, ch):
00757     """
00758     Return number of `ch` characters at the start of `line`.
00759 
00760     Example:
00761 
00762     >>> _count_leading('   abc', ' ')
00763     3
00764     """
00765 
00766     i, n = 0, len(line)
00767     while i < n and line[i] == ch:
00768         i += 1
00769     return i

Here is the caller graph for this function:

def MoinMoin.support.difflib._mdiff (   fromlines,
  tolines,
  context = None,
  linejunk = None,
  charjunk = IS_CHARACTER_JUNK 
) [private]

Definition at line 1320 of file difflib.py.

01320 
01321            charjunk=IS_CHARACTER_JUNK):
01322     r"""Returns generator yielding marked up from/to side by side differences.
01323 
01324     Arguments:
01325     fromlines -- list of text lines to compared to tolines
01326     tolines -- list of text lines to be compared to fromlines
01327     context -- number of context lines to display on each side of difference,
01328                if None, all from/to text lines will be generated.
01329     linejunk -- passed on to ndiff (see ndiff documentation)
01330     charjunk -- passed on to ndiff (see ndiff documentation)
01331 
01332     This function returns an interator which returns a tuple:
01333     (from line tuple, to line tuple, boolean flag)
01334 
01335     from/to line tuple -- (line num, line text)
01336         line num -- integer or None (to indicate a context seperation)
01337         line text -- original line text with following markers inserted:
01338             '\0+' -- marks start of added text
01339             '\0-' -- marks start of deleted text
01340             '\0^' -- marks start of changed text
01341             '\1' -- marks end of added/deleted/changed text
01342 
01343     boolean flag -- None indicates context separation, True indicates
01344         either "from" or "to" line contains a change, otherwise False.
01345 
01346     This function/iterator was originally developed to generate side by side
01347     file difference for making HTML pages (see HtmlDiff class for example
01348     usage).
01349 
01350     Note, this function utilizes the ndiff function to generate the side by
01351     side difference markup.  Optional ndiff arguments may be passed to this
01352     function and they in turn will be passed to ndiff.
01353     """
01354     import re
01355 
01356     # regular expression for finding intraline change indices
01357     change_re = re.compile('(\++|\-+|\^+)')
01358 
01359     # create the difference iterator to generate the differences
01360     diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)
01361 
01362     def _make_line(lines, format_key, side, num_lines=[0,0]):
01363         """Returns line of text with user's change markup and line formatting.
01364 
01365         lines -- list of lines from the ndiff generator to produce a line of
01366                  text from.  When producing the line of text to return, the
01367                  lines used are removed from this list.
01368         format_key -- '+' return first line in list with "add" markup around
01369                           the entire line.
01370                       '-' return first line in list with "delete" markup around
01371                           the entire line.
01372                       '?' return first line in list with add/delete/change
01373                           intraline markup (indices obtained from second line)
01374                       None return first line in list with no markup
01375         side -- indice into the num_lines list (0=from,1=to)
01376         num_lines -- from/to current line number.  This is NOT intended to be a
01377                      passed parameter.  It is present as a keyword argument to
01378                      maintain memory of the current line numbers between calls
01379                      of this function.
01380 
01381         Note, this function is purposefully not defined at the module scope so
01382         that data it needs from its parent function (within whose context it
01383         is defined) does not need to be of module scope.
01384         """
01385         num_lines[side] += 1
01386         # Handle case where no user markup is to be added, just return line of
01387         # text with user's line format to allow for usage of the line number.
01388         if format_key is None:
01389             return (num_lines[side],lines.pop(0)[2:])
01390         # Handle case of intraline changes
01391         if format_key == '?':
01392             text, markers = lines.pop(0), lines.pop(0)
01393             # find intraline changes (store change type and indices in tuples)
01394             sub_info = []
01395             def record_sub_info(match_object,sub_info=sub_info):
01396                 sub_info.append([match_object.group(1)[0],match_object.span()])
01397                 return match_object.group(1)
01398             change_re.sub(record_sub_info,markers)
01399             # process each tuple inserting our special marks that won't be
01400             # noticed by an xml/html escaper.
01401             for key,(begin,end) in sub_info[::-1]:
01402                 text = text[0:begin]+'\0'+key+text[begin:end]+'\1'+text[end:]
01403             text = text[2:]
01404         # Handle case of add/delete entire line
01405         else:
01406             text = lines.pop(0)[2:]
01407             # if line of text is just a newline, insert a space so there is
01408             # something for the user to highlight and see.
01409             if not text:
01410                 text = ' '
01411             # insert marks that won't be noticed by an xml/html escaper.
01412             text = '\0' + format_key + text + '\1'
01413         # Return line of text, first allow user's line formatter to do its
01414         # thing (such as adding the line number) then replace the special
01415         # marks with what the user's change markup.
01416         return (num_lines[side],text)
01417 
01418     def _line_iterator():
01419         """Yields from/to lines of text with a change indication.
01420 
01421         This function is an iterator.  It itself pulls lines from a
01422         differencing iterator, processes them and yields them.  When it can
01423         it yields both a "from" and a "to" line, otherwise it will yield one
01424         or the other.  In addition to yielding the lines of from/to text, a
01425         boolean flag is yielded to indicate if the text line(s) have
01426         differences in them.
01427 
01428         Note, this function is purposefully not defined at the module scope so
01429         that data it needs from its parent function (within whose context it
01430         is defined) does not need to be of module scope.
01431         """
01432         lines = []
01433         num_blanks_pending, num_blanks_to_yield = 0, 0
01434         while True:
01435             # Load up next 4 lines so we can look ahead, create strings which
01436             # are a concatenation of the first character of each of the 4 lines
01437             # so we can do some very readable comparisons.
01438             while len(lines) < 4:
01439                 try:
01440                     lines.append(diff_lines_iterator.next())
01441                 except StopIteration:
01442                     lines.append('X')
01443             s = ''.join([line[0] for line in lines])
01444             if s.startswith('X'):
01445                 # When no more lines, pump out any remaining blank lines so the
01446                 # corresponding add/delete lines get a matching blank line so
01447                 # all line pairs get yielded at the next level.
01448                 num_blanks_to_yield = num_blanks_pending
01449             elif s.startswith('-?+?'):
01450                 # simple intraline change
01451                 yield _make_line(lines,'?',0), _make_line(lines,'?',1), True
01452                 continue
01453             elif s.startswith('--++'):
01454                 # in delete block, add block coming: we do NOT want to get
01455                 # caught up on blank lines yet, just process the delete line
01456                 num_blanks_pending -= 1
01457                 yield _make_line(lines,'-',0), None, True
01458                 continue
01459             elif s.startswith('--?+') or \
01460                  s.startswith('--+') or \
01461                  s.startswith('- '):
01462                 # in delete block and see a intraline change or unchanged line
01463                 # coming: yield the delete line and then blanks
01464                 from_line,to_line = _make_line(lines,'-',0), None
01465                 num_blanks_to_yield,num_blanks_pending = num_blanks_pending-1,0
01466             elif s.startswith('-+?'):
01467                 # intraline change
01468                 yield _make_line(lines,None,0), _make_line(lines,'?',1), True
01469                 continue
01470             elif s.startswith('-?+'):
01471                 # intraline change
01472                 yield _make_line(lines,'?',0), _make_line(lines,None,1), True
01473                 continue
01474             elif s.startswith('-'):
01475                 # delete FROM line
01476                 num_blanks_pending -= 1
01477                 yield _make_line(lines,'-',0), None, True
01478                 continue
01479             elif s.startswith('+--'):
01480                 # in add block, delete block coming: we do NOT want to get
01481                 # caught up on blank lines yet, just process the add line
01482                 num_blanks_pending += 1
01483                 yield None, _make_line(lines,'+',1), True
01484                 continue
01485             elif s.startswith('+ ') or \
01486                  s.startswith('+-'):
01487                 # will be leaving an add block: yield blanks then add line
01488                 from_line, to_line = None, _make_line(lines,'+',1)
01489                 num_blanks_to_yield,num_blanks_pending = num_blanks_pending+1,0
01490             elif s.startswith('+'):
01491                 # inside an add block, yield the add line
01492                 num_blanks_pending += 1
01493                 yield None, _make_line(lines,'+',1), True
01494                 continue
01495             elif s.startswith(' '):
01496                 # unchanged text, yield it to both sides
01497                 yield _make_line(lines[:],None,0),_make_line(lines,None,1),False
01498                 continue
01499             # Catch up on the blank lines so when we yield the next from/to
01500             # pair, they are lined up.
01501             while(num_blanks_to_yield < 0):
01502                 num_blanks_to_yield += 1
01503                 yield None,('','\n'),True
01504             while(num_blanks_to_yield > 0):
01505                 num_blanks_to_yield -= 1
01506                 yield ('','\n'),None,True
01507             if s.startswith('X'):
01508                 raise StopIteration
01509             else:
01510                 yield from_line,to_line,True
01511 
01512     def _line_pair_iterator():
01513         """Yields from/to lines of text with a change indication.
01514 
01515         This function is an iterator.  It itself pulls lines from the line
01516         iterator.  Its difference from that iterator is that this function
01517         always yields a pair of from/to text lines (with the change
01518         indication).  If necessary it will collect single from/to lines
01519         until it has a matching pair from/to pair to yield.
01520 
01521         Note, this function is purposefully not defined at the module scope so
01522         that data it needs from its parent function (within whose context it
01523         is defined) does not need to be of module scope.
01524         """
01525         line_iterator = _line_iterator()
01526         fromlines,tolines=[],[]
01527         while True:
01528             # Collecting lines of text until we have a from/to pair
01529             while (len(fromlines)==0 or len(tolines)==0):
01530                 from_line, to_line, found_diff =line_iterator.next()
01531                 if from_line is not None:
01532                     fromlines.append((from_line,found_diff))
01533                 if to_line is not None:
01534                     tolines.append((to_line,found_diff))
01535             # Once we have a pair, remove them from the collection and yield it
01536             from_line, fromDiff = fromlines.pop(0)
01537             to_line, to_diff = tolines.pop(0)
01538             yield (from_line,to_line,fromDiff or to_diff)
01539 
01540     # Handle case where user does not want context differencing, just yield
01541     # them up without doing anything else with them.
01542     line_pair_iterator = _line_pair_iterator()
01543     if context is None:
01544         while True:
01545             yield line_pair_iterator.next()
01546     # Handle case where user wants context differencing.  We must do some
01547     # storage of lines until we know for sure that they are to be yielded.
01548     else:
01549         context += 1
01550         lines_to_write = 0
01551         while True:
01552             # Store lines up until we find a difference, note use of a
01553             # circular queue because we only need to keep around what
01554             # we need for context.
01555             index, contextLines = 0, [None]*(context)
01556             found_diff = False
01557             while(found_diff is False):
01558                 from_line, to_line, found_diff = line_pair_iterator.next()
01559                 i = index % context
01560                 contextLines[i] = (from_line, to_line, found_diff)
01561                 index += 1
01562             # Yield lines that we have collected so far, but first yield
01563             # the user's separator.
01564             if index > context:
01565                 yield None, None, None
01566                 lines_to_write = context
01567             else:
01568                 lines_to_write = index
01569                 index = 0
01570             while(lines_to_write):
01571                 i = index % context
01572                 index += 1
01573                 yield contextLines[i]
01574                 lines_to_write -= 1
01575             # Now yield the context lines after the change
01576             lines_to_write = context-1
01577             while(lines_to_write):
01578                 from_line, to_line, found_diff = line_pair_iterator.next()
01579                 # If another change within the context, extend the context
01580                 if found_diff:
01581                     lines_to_write = context-1
01582                 else:
01583                     lines_to_write -= 1
01584                 yield from_line, to_line, found_diff
01585 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.difflib._test ( ) [private]

Definition at line 2024 of file difflib.py.

02024 
02025 def _test():
02026     import doctest, difflib
02027     return doctest.testmod(difflib)

Here is the caller graph for this function:

def MoinMoin.support.difflib.context_diff (   a,
  b,
  fromfile = '',
  tofile = '',
  fromfiledate = '',
  tofiledate = '',
  n = 3,
  lineterm = '\n' 
)

Definition at line 1209 of file difflib.py.

01209 
01210                  fromfiledate='', tofiledate='', n=3, lineterm='\n'):
01211     r"""
01212     Compare two sequences of lines; generate the delta as a context diff.
01213 
01214     Context diffs are a compact way of showing line changes and a few
01215     lines of context.  The number of context lines is set by 'n' which
01216     defaults to three.
01217 
01218     By default, the diff control lines (those with *** or ---) are
01219     created with a trailing newline.  This is helpful so that inputs
01220     created from file.readlines() result in diffs that are suitable for
01221     file.writelines() since both the inputs and outputs have trailing
01222     newlines.
01223 
01224     For inputs that do not have trailing newlines, set the lineterm
01225     argument to "" so that the output will be uniformly newline free.
01226 
01227     The context diff format normally has a header for filenames and
01228     modification times.  Any or all of these may be specified using
01229     strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
01230     The modification times are normally expressed in the format returned
01231     by time.ctime().  If not specified, the strings default to blanks.
01232 
01233     Example:
01234 
01235     >>> print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1),
01236     ...       'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current',
01237     ...       'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')),
01238     *** Original Sat Jan 26 23:30:50 1991
01239     --- Current Fri Jun 06 10:22:46 2003
01240     ***************
01241     *** 1,4 ****
01242       one
01243     ! two
01244     ! three
01245       four
01246     --- 1,4 ----
01247     + zero
01248       one
01249     ! tree
01250       four
01251     """
01252 
01253     started = False
01254     prefixmap = {'insert':'+ ', 'delete':'- ', 'replace':'! ', 'equal':'  '}
01255     for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):
01256         if not started:
01257             yield '*** %s %s%s' % (fromfile, fromfiledate, lineterm)
01258             yield '--- %s %s%s' % (tofile, tofiledate, lineterm)
01259             started = True
01260 
01261         yield '***************%s' % (lineterm,)
01262         if group[-1][2] - group[0][1] >= 2:
01263             yield '*** %d,%d ****%s' % (group[0][1]+1, group[-1][2], lineterm)
01264         else:
01265             yield '*** %d ****%s' % (group[-1][2], lineterm)
01266         visiblechanges = [e for e in group if e[0] in ('replace', 'delete')]
01267         if visiblechanges:
01268             for tag, i1, i2, _, _ in group:
01269                 if tag != 'insert':
01270                     for line in a[i1:i2]:
01271                         yield prefixmap[tag] + line
01272 
01273         if group[-1][4] - group[0][3] >= 2:
01274             yield '--- %d,%d ----%s' % (group[0][3]+1, group[-1][4], lineterm)
01275         else:
01276             yield '--- %d ----%s' % (group[-1][4], lineterm)
01277         visiblechanges = [e for e in group if e[0] in ('replace', 'insert')]
01278         if visiblechanges:
01279             for tag, _, _, j1, j2 in group:
01280                 if tag != 'delete':
01281                     for line in b[j1:j2]:
01282                         yield prefixmap[tag] + line

Here is the caller graph for this function:

def MoinMoin.support.difflib.get_close_matches (   word,
  possibilities,
  n = 3,
  cutoff = 0.6 
)
Use SequenceMatcher to return list of the best "good enough" matches.

word is a sequence for which close matches are desired (typically a
string).

possibilities is a list of sequences against which to match word
(typically a list of strings).

Optional arg n (default 3) is the maximum number of close matches to
return.  n must be > 0.

Optional arg cutoff (default 0.6) is a float in [0, 1].  Possibilities
that don't score at least that similar to word are ignored.

The best (no more than n) matches among the possibilities are returned
in a list, sorted by similarity score, most similar first.

>>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
['apple', 'ape']
>>> import keyword as _keyword
>>> get_close_matches("wheel", _keyword.kwlist)
['while']
>>> get_close_matches("apple", _keyword.kwlist)
[]
>>> get_close_matches("accept", _keyword.kwlist)
['except']

Definition at line 703 of file difflib.py.

00703 
00704 def get_close_matches(word, possibilities, n=3, cutoff=0.6):
00705     """Use SequenceMatcher to return list of the best "good enough" matches.
00706 
00707     word is a sequence for which close matches are desired (typically a
00708     string).
00709 
00710     possibilities is a list of sequences against which to match word
00711     (typically a list of strings).
00712 
00713     Optional arg n (default 3) is the maximum number of close matches to
00714     return.  n must be > 0.
00715 
00716     Optional arg cutoff (default 0.6) is a float in [0, 1].  Possibilities
00717     that don't score at least that similar to word are ignored.
00718 
00719     The best (no more than n) matches among the possibilities are returned
00720     in a list, sorted by similarity score, most similar first.
00721 
00722     >>> get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
00723     ['apple', 'ape']
00724     >>> import keyword as _keyword
00725     >>> get_close_matches("wheel", _keyword.kwlist)
00726     ['while']
00727     >>> get_close_matches("apple", _keyword.kwlist)
00728     []
00729     >>> get_close_matches("accept", _keyword.kwlist)
00730     ['except']
00731     """
00732 
00733     if not n >  0:
00734         raise ValueError("n must be > 0: %r" % (n,))
00735     if not 0.0 <= cutoff <= 1.0:
00736         raise ValueError("cutoff must be in [0.0, 1.0]: %r" % (cutoff,))
00737     result = []
00738     s = SequenceMatcher()
00739     s.set_seq2(word)
00740     for x in possibilities:
00741         s.set_seq1(x)
00742         if s.real_quick_ratio() >= cutoff and \
00743            s.quick_ratio() >= cutoff and \
00744            s.ratio() >= cutoff:
00745             result.append((s.ratio(), x))
00746 
00747     # Sort by score.    
00748     result.sort()   
00749     # Retain only the best n.   
00750     result = result[-n:]    
00751     # Move best-scorer to head of list.     
00752     result.reverse()    
00753     # Strip scores.     
00754     return [x for score, x in result]

def MoinMoin.support.difflib.IS_CHARACTER_JUNK (   ch,
  ws = " \t" 
)

Definition at line 1127 of file difflib.py.

01127 
01128 def IS_CHARACTER_JUNK(ch, ws=" \t"):
01129     r"""
01130     Return 1 for ignorable character: iff `ch` is a space or tab.
01131 
01132     Examples:
01133 
01134     >>> IS_CHARACTER_JUNK(' ')
01135     True
01136     >>> IS_CHARACTER_JUNK('\t')
01137     True
01138     >>> IS_CHARACTER_JUNK('\n')
01139     False
01140     >>> IS_CHARACTER_JUNK('x')
01141     False
01142     """
01143 
01144     return ch in ws
01145 

Here is the call graph for this function:

def MoinMoin.support.difflib.IS_LINE_JUNK (   line,
  pat = re.compile(r"\s*#?\s*$").match 
)

Definition at line 1111 of file difflib.py.

01111 
01112 def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match):
01113     r"""
01114     Return 1 for ignorable line: iff `line` is blank or contains a single '#'.
01115 
01116     Examples:
01117 
01118     >>> IS_LINE_JUNK('\n')
01119     True
01120     >>> IS_LINE_JUNK('  #   \n')
01121     True
01122     >>> IS_LINE_JUNK('hello\n')
01123     False
01124     """
01125 
01126     return pat(line) is not None

def MoinMoin.support.difflib.ndiff (   a,
  b,
  linejunk = None,
  charjunk = IS_CHARACTER_JUNK 
)

Definition at line 1283 of file difflib.py.

01283 
01284 def ndiff(a, b, linejunk=None, charjunk=IS_CHARACTER_JUNK):
01285     r"""
01286     Compare `a` and `b` (lists of strings); return a `Differ`-style delta.
01287 
01288     Optional keyword parameters `linejunk` and `charjunk` are for filter
01289     functions (or None):
01290 
01291     - linejunk: A function that should accept a single string argument, and
01292       return true iff the string is junk.  The default is None, and is
01293       recommended; as of Python 2.3, an adaptive notion of "noise" lines is
01294       used that does a good job on its own.
01295 
01296     - charjunk: A function that should accept a string of length 1. The
01297       default is module-level function IS_CHARACTER_JUNK, which filters out
01298       whitespace characters (a blank or tab; note: bad idea to include newline
01299       in this!).
01300 
01301     Tools/scripts/ndiff.py is a command-line front-end to this function.
01302 
01303     Example:
01304 
01305     >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
01306     ...              'ore\ntree\nemu\n'.splitlines(1))
01307     >>> print ''.join(diff),
01308     - one
01309     ?  ^
01310     + ore
01311     ?  ^
01312     - two
01313     - three
01314     ?  -
01315     + tree
01316     + emu
01317     """
01318     return Differ(linejunk, charjunk).compare(a, b)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.difflib.restore (   delta,
  which 
)

Definition at line 1992 of file difflib.py.

01992 
01993 def restore(delta, which):
01994     r"""
01995     Generate one of the two sequences that generated a delta.
01996 
01997     Given a `delta` produced by `Differ.compare()` or `ndiff()`, extract
01998     lines originating from file 1 or 2 (parameter `which`), stripping off line
01999     prefixes.
02000 
02001     Examples:
02002 
02003     >>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
02004     ...              'ore\ntree\nemu\n'.splitlines(1))
02005     >>> diff = list(diff)
02006     >>> print ''.join(restore(diff, 1)),
02007     one
02008     two
02009     three
02010     >>> print ''.join(restore(diff, 2)),
02011     ore
02012     tree
02013     emu
02014     """
02015     try:
02016         tag = {1: "- ", 2: "+ "}[int(which)]
02017     except KeyError:
02018         raise ValueError, ('unknown delta choice (must be 1 or 2): %r'
02019                            % which)
02020     prefixes = ("  ", tag)
02021     for line in delta:
02022         if line[:2] in prefixes:
02023             yield line[2:]

def MoinMoin.support.difflib.unified_diff (   a,
  b,
  fromfile = '',
  tofile = '',
  fromfiledate = '',
  tofiledate = '',
  n = 3,
  lineterm = '\n' 
)

Definition at line 1147 of file difflib.py.

01147 
01148                  tofiledate='', n=3, lineterm='\n'):
01149     r"""
01150     Compare two sequences of lines; generate the delta as a unified diff.
01151 
01152     Unified diffs are a compact way of showing line changes and a few
01153     lines of context.  The number of context lines is set by 'n' which
01154     defaults to three.
01155 
01156     By default, the diff control lines (those with ---, +++, or @@) are
01157     created with a trailing newline.  This is helpful so that inputs
01158     created from file.readlines() result in diffs that are suitable for
01159     file.writelines() since both the inputs and outputs have trailing
01160     newlines.
01161 
01162     For inputs that do not have trailing newlines, set the lineterm
01163     argument to "" so that the output will be uniformly newline free.
01164 
01165     The unidiff format normally has a header for filenames and modification
01166     times.  Any or all of these may be specified using strings for
01167     'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.  The modification
01168     times are normally expressed in the format returned by time.ctime().
01169 
01170     Example:
01171 
01172     >>> for line in unified_diff('one two three four'.split(),
01173     ...             'zero one tree four'.split(), 'Original', 'Current',
01174     ...             'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:20:52 2003',
01175     ...             lineterm=''):
01176     ...     print line
01177     --- Original Sat Jan 26 23:30:50 1991
01178     +++ Current Fri Jun 06 10:20:52 2003
01179     @@ -1,4 +1,4 @@
01180     +zero
01181      one
01182     -two
01183     -three
01184     +tree
01185      four
01186     """
01187 
01188     started = False
01189     for group in SequenceMatcher(None,a,b).get_grouped_opcodes(n):
01190         if not started:
01191             yield '--- %s %s%s' % (fromfile, fromfiledate, lineterm)
01192             yield '+++ %s %s%s' % (tofile, tofiledate, lineterm)
01193             started = True
01194         i1, i2, j1, j2 = group[0][1], group[-1][2], group[0][3], group[-1][4]
01195         yield "@@ -%d,%d +%d,%d @@%s" % (i1+1, i2-i1, j1+1, j2-j1, lineterm)
01196         for tag, i1, i2, j1, j2 in group:
01197             if tag == 'equal':
01198                 for line in a[i1:i2]:
01199                     yield ' ' + line
01200                 continue
01201             if tag == 'replace' or tag == 'delete':
01202                 for line in a[i1:i2]:
01203                     yield '-' + line
01204             if tag == 'replace' or tag == 'insert':
01205                 for line in b[j1:j2]:
01206                     yield '+' + line
01207 
# See http://www.unix.org/single_unix_specification/

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 ['get_close_matches', 'ndiff', 'restore', 'SequenceMatcher',
00002            'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff',
00003            'unified_diff', 'HtmlDiff']

Definition at line 36 of file difflib.py.

Initial value:
00001 """
00002 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
00003           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
00004 
00005 <html>
00006 
00007 <head>
00008     <meta http-equiv="Content-Type"
00009           content="text/html; charset=ISO-8859-1" />
00010     <title></title>
00011     <style type="text/css">%(styles)s
00012     </style>
00013 </head>
00014 
00015 <body>
00016     %(table)s%(legend)s
00017 </body>
00018 
00019 </html>"""

Definition at line 1586 of file difflib.py.

Initial value:
00001 """
00002     <table class="diff" summary="Legends">
00003         <tr> <th colspan="2"> Legends </th> </tr>
00004         <tr> <td> <table border="" summary="Colors">
00005                       <tr><th> Colors </th> </tr>
00006                       <tr><td class="diff_add">&nbsp;Added&nbsp;</td></tr>
00007                       <tr><td class="diff_chg">Changed</td> </tr>
00008                       <tr><td class="diff_sub">Deleted</td> </tr>
00009                   </table></td>
00010              <td> <table border="" summary="Links">
00011                       <tr><th colspan="2"> Links </th> </tr>
00012                       <tr><td>(f)irst change</td> </tr>
00013                       <tr><td>(n)ext change</td> </tr>
00014                       <tr><td>(t)op</td> </tr>
00015                   </table></td> </tr>
00016     </table>"""

Definition at line 1625 of file difflib.py.

Initial value:
00001 """
00002         table.diff {font-family:Courier; border:medium;}
00003         .diff_header {background-color:#e0e0e0}
00004         td.diff_header {text-align:right}
00005         .diff_next {background-color:#c0c0c0}
00006         .diff_add {background-color:#aaffaa}
00007         .diff_chg {background-color:#ffff77}
00008         .diff_sub {background-color:#ffaaaa}"""

Definition at line 1606 of file difflib.py.

Initial value:
00001 """
00002     <table class="diff" id="difflib_chg_%(prefix)s_top"
00003            cellspacing="0" cellpadding="0" rules="groups" >
00004         <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
00005         <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
00006         %(header_row)s
00007         <tbody>
00008 %(data_rows)s        </tbody>
00009     </table>"""

Definition at line 1615 of file difflib.py.