changeset 3922:827328a403f1

difflib: improve 2.3 compatibility, fix HtmlDiff
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 29 Jul 2008 22:08:48 +0200
parents 4353a470388e
children 49bb3b6e3ab5 44d856f8a110
files MoinMoin/support/difflib.py
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/support/difflib.py	Tue Jul 29 18:23:17 2008 +0200
+++ b/MoinMoin/support/difflib.py	Tue Jul 29 22:08:48 2008 +0200
@@ -1,8 +1,9 @@
 #! /usr/bin/env python
 # Python 2.4.3 (maybe other versions, too) has a broken difflib, sometimes
 # raising a "maximum recursion depth exceeded in cmp" exception.
-# This is taken from python.org SVN repo revision 46940 with patches
+# This is taken from python.org SVN repo revision 54230 with patches
 # 36160 and 34415 reversed for python2.3 compatibility.
+# Also, startswith(tuple) [2.5] was changed to multiple startswith(elem).
 
 """
 Module difflib -- helpers for computing deltas between objects.
@@ -1317,7 +1318,7 @@
 
 def _mdiff(fromlines, tolines, context=None, linejunk=None,
            charjunk=IS_CHARACTER_JUNK):
-    """Returns generator yielding marked up from/to side by side differences.
+    r"""Returns generator yielding marked up from/to side by side differences.
 
     Arguments:
     fromlines -- list of text lines to compared to tolines
@@ -1454,7 +1455,9 @@
                 num_blanks_pending -= 1
                 yield _make_line(lines,'-',0), None, True
                 continue
-            elif s.startswith(('--?+', '--+', '- ')):
+            elif s.startswith('--?+') or \
+                 s.startswith('--+') or \
+                 s.startswith('- '):
                 # in delete block and see a intraline change or unchanged line
                 # coming: yield the delete line and then blanks
                 from_line,to_line = _make_line(lines,'-',0), None
@@ -1478,7 +1481,8 @@
                 num_blanks_pending += 1
                 yield None, _make_line(lines,'+',1), True
                 continue
-            elif s.startswith(('+ ', '+-')):
+            elif s.startswith('+ ') or \
+                 s.startswith('+-'):
                 # will be leaving an add block: yield blanks then add line
                 from_line, to_line = None, _make_line(lines,'+',1)
                 num_blanks_to_yield,num_blanks_pending = num_blanks_pending+1,0
@@ -1951,8 +1955,7 @@
         fromlist,tolist,flaglist,next_href,next_id = self._convert_flags(
             fromlist,tolist,flaglist,context,numlines)
 
-        import cStringIO
-        s = cStringIO.StringIO()
+        s = []
         fmt = '            <tr><td class="diff_next"%s>%s</td>%s' + \
               '<td class="diff_next">%s</td>%s</tr>\n'
         for i in range(len(flaglist)):
@@ -1960,9 +1963,9 @@
                 # mdiff yields None on separator lines skip the bogus ones
                 # generated for the first line
                 if i > 0:
-                    s.write('        </tbody>        \n        <tbody>\n')
+                    s.append('        </tbody>        \n        <tbody>\n')
             else:
-                s.write( fmt % (next_id[i],next_href[i],fromlist[i],
+                s.append( fmt % (next_id[i],next_href[i],fromlist[i],
                                            next_href[i],tolist[i]))
         if fromdesc or todesc:
             header_row = '<thead><tr>%s%s%s%s</tr></thead>' % (
@@ -1974,7 +1977,7 @@
             header_row = ''
 
         table = self._table_template % dict(
-            data_rows=s.getvalue(),
+            data_rows=''.join(s),
             header_row=header_row,
             prefix=self._prefix[1])