~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/support/difflib.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/env python
2
2
# Python 2.4.3 (maybe other versions, too) has a broken difflib, sometimes
3
3
# raising a "maximum recursion depth exceeded in cmp" exception.
4
 
# This is taken from python.org SVN repo revision 54230 with patches
 
4
# This is taken from python.org SVN repo revision 46940 with patches
5
5
# 36160 and 34415 reversed for python2.3 compatibility.
6
 
# Also, startswith(tuple) [2.5] was changed to multiple startswith(elem).
7
6
 
8
7
"""
9
8
Module difflib -- helpers for computing deltas between objects.
1318
1317
 
1319
1318
def _mdiff(fromlines, tolines, context=None, linejunk=None,
1320
1319
           charjunk=IS_CHARACTER_JUNK):
1321
 
    r"""Returns generator yielding marked up from/to side by side differences.
 
1320
    """Returns generator yielding marked up from/to side by side differences.
1322
1321
 
1323
1322
    Arguments:
1324
1323
    fromlines -- list of text lines to compared to tolines
1455
1454
                num_blanks_pending -= 1
1456
1455
                yield _make_line(lines,'-',0), None, True
1457
1456
                continue
1458
 
            elif s.startswith('--?+') or \
1459
 
                 s.startswith('--+') or \
1460
 
                 s.startswith('- '):
 
1457
            elif s.startswith(('--?+', '--+', '- ')):
1461
1458
                # in delete block and see a intraline change or unchanged line
1462
1459
                # coming: yield the delete line and then blanks
1463
1460
                from_line,to_line = _make_line(lines,'-',0), None
1481
1478
                num_blanks_pending += 1
1482
1479
                yield None, _make_line(lines,'+',1), True
1483
1480
                continue
1484
 
            elif s.startswith('+ ') or \
1485
 
                 s.startswith('+-'):
 
1481
            elif s.startswith(('+ ', '+-')):
1486
1482
                # will be leaving an add block: yield blanks then add line
1487
1483
                from_line, to_line = None, _make_line(lines,'+',1)
1488
1484
                num_blanks_to_yield,num_blanks_pending = num_blanks_pending+1,0
1955
1951
        fromlist,tolist,flaglist,next_href,next_id = self._convert_flags(
1956
1952
            fromlist,tolist,flaglist,context,numlines)
1957
1953
 
1958
 
        s = []
 
1954
        import cStringIO
 
1955
        s = cStringIO.StringIO()
1959
1956
        fmt = '            <tr><td class="diff_next"%s>%s</td>%s' + \
1960
1957
              '<td class="diff_next">%s</td>%s</tr>\n'
1961
1958
        for i in range(len(flaglist)):
1963
1960
                # mdiff yields None on separator lines skip the bogus ones
1964
1961
                # generated for the first line
1965
1962
                if i > 0:
1966
 
                    s.append('        </tbody>        \n        <tbody>\n')
 
1963
                    s.write('        </tbody>        \n        <tbody>\n')
1967
1964
            else:
1968
 
                s.append( fmt % (next_id[i],next_href[i],fromlist[i],
 
1965
                s.write( fmt % (next_id[i],next_href[i],fromlist[i],
1969
1966
                                           next_href[i],tolist[i]))
1970
1967
        if fromdesc or todesc:
1971
1968
            header_row = '<thead><tr>%s%s%s%s</tr></thead>' % (
1977
1974
            header_row = ''
1978
1975
 
1979
1976
        table = self._table_template % dict(
1980
 
            data_rows=''.join(s),
 
1977
            data_rows=s.getvalue(),
1981
1978
            header_row=header_row,
1982
1979
            prefix=self._prefix[1])
1983
1980