Commit afb5f942 authored by Tim Peters's avatar Tim Peters

Reverting whitespace normalization. test_difflib fails with it -- the

test depends on invisible trailing whitespace in .py files.  The author will
have to repair that.
parent 45e77c55
...@@ -1289,7 +1289,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, ...@@ -1289,7 +1289,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
if None, all from/to text lines will be generated. if None, all from/to text lines will be generated.
linejunk -- passed on to ndiff (see ndiff documentation) linejunk -- passed on to ndiff (see ndiff documentation)
charjunk -- passed on to ndiff (see ndiff documentation) charjunk -- passed on to ndiff (see ndiff documentation)
This function returns an interator which returns a tuple: This function returns an interator which returns a tuple:
(from line tuple, to line tuple, boolean flag) (from line tuple, to line tuple, boolean flag)
...@@ -1300,7 +1300,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, ...@@ -1300,7 +1300,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
'\0-' -- marks start of deleted text '\0-' -- marks start of deleted text
'\0^' -- marks start of changed text '\0^' -- marks start of changed text
'\1' -- marks end of added/deleted/changed text '\1' -- marks end of added/deleted/changed text
boolean flag -- None indicates context separation, True indicates boolean flag -- None indicates context separation, True indicates
either "from" or "to" line contains a change, otherwise False. either "from" or "to" line contains a change, otherwise False.
...@@ -1310,13 +1310,13 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, ...@@ -1310,13 +1310,13 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
Note, this function utilizes the ndiff function to generate the side by Note, this function utilizes the ndiff function to generate the side by
side difference markup. Optional ndiff arguments may be passed to this side difference markup. Optional ndiff arguments may be passed to this
function and they in turn will be passed to ndiff. function and they in turn will be passed to ndiff.
""" """
import re import re
# regular expression for finding intraline change indices # regular expression for finding intraline change indices
change_re = re.compile('(\++|\-+|\^+)') change_re = re.compile('(\++|\-+|\^+)')
# create the difference iterator to generate the differences # create the difference iterator to generate the differences
diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk) diff_lines_iterator = ndiff(fromlines,tolines,linejunk,charjunk)
...@@ -1375,7 +1375,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, ...@@ -1375,7 +1375,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
# thing (such as adding the line number) then replace the special # thing (such as adding the line number) then replace the special
# marks with what the user's change markup. # marks with what the user's change markup.
return (num_lines[side],text) return (num_lines[side],text)
def _line_iterator(): def _line_iterator():
"""Yields from/to lines of text with a change indication. """Yields from/to lines of text with a change indication.
...@@ -1392,7 +1392,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None, ...@@ -1392,7 +1392,7 @@ def _mdiff(fromlines, tolines, context=None, linejunk=None,
""" """
lines = [] lines = []
num_blanks_pending, num_blanks_to_yield = 0, 0 num_blanks_pending, num_blanks_to_yield = 0, 0
while True: while True:
# Load up next 4 lines so we can look ahead, create strings which # Load up next 4 lines so we can look ahead, create strings which
# are a concatenation of the first character of each of the 4 lines # are a concatenation of the first character of each of the 4 lines
# so we can do some very readable comparisons. # so we can do some very readable comparisons.
...@@ -1550,7 +1550,7 @@ _file_template = """ ...@@ -1550,7 +1550,7 @@ _file_template = """
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" <meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1" /> content="text/html; charset=ISO-8859-1" />
<title></title> <title></title>
<style type="text/css">%(styles)s <style type="text/css">%(styles)s
...@@ -1573,9 +1573,9 @@ _styles = """ ...@@ -1573,9 +1573,9 @@ _styles = """
.diff_sub {background-color:#ffaaaa}""" .diff_sub {background-color:#ffaaaa}"""
_table_template = """ _table_template = """
<table class="diff" id="difflib_chg_%(prefix)s_top" <table class="diff" id="difflib_chg_%(prefix)s_top"
cellspacing="0" cellpadding="0" rules="groups" > cellspacing="0" cellpadding="0" rules="groups" >
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
%(header_row)s %(header_row)s
<tbody> <tbody>
...@@ -1604,15 +1604,15 @@ class HtmlDiff(object): ...@@ -1604,15 +1604,15 @@ class HtmlDiff(object):
This class can be used to create an HTML table (or a complete HTML file This class can be used to create an HTML table (or a complete HTML file
containing the table) showing a side by side, line by line comparision containing the table) showing a side by side, line by line comparision
of text with inter-line and intra-line change highlights. The table can of text with inter-line and intra-line change highlights. The table can
be generated in either full or contextual difference mode. be generated in either full or contextual difference mode.
The following methods are provided for HTML generation: The following methods are provided for HTML generation:
make_table -- generates HTML for a single side by side table make_table -- generates HTML for a single side by side table
make_file -- generates complete HTML file with a single side by side table make_file -- generates complete HTML file with a single side by side table
See tools/scripts/diff.py for an example usage of this class. See tools/scripts/diff.py for an example usage of this class.
""" """
_file_template = _file_template _file_template = _file_template
...@@ -1620,7 +1620,7 @@ class HtmlDiff(object): ...@@ -1620,7 +1620,7 @@ class HtmlDiff(object):
_table_template = _table_template _table_template = _table_template
_legend = _legend _legend = _legend
_default_prefix = 0 _default_prefix = 0
def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None, def __init__(self,tabsize=8,wrapcolumn=None,linejunk=None,
charjunk=IS_CHARACTER_JUNK): charjunk=IS_CHARACTER_JUNK):
"""HtmlDiff instance initializer """HtmlDiff instance initializer
...@@ -1630,7 +1630,7 @@ class HtmlDiff(object): ...@@ -1630,7 +1630,7 @@ class HtmlDiff(object):
wrapcolumn -- column number where lines are broken and wrapped, wrapcolumn -- column number where lines are broken and wrapped,
defaults to None where lines are not wrapped. defaults to None where lines are not wrapped.
linejunk,charjunk -- keyword arguments passed into ndiff() (used to by linejunk,charjunk -- keyword arguments passed into ndiff() (used to by
HtmlDiff() to generate the side by side HTML differences). See HtmlDiff() to generate the side by side HTML differences). See
ndiff() documentation for argument default values and descriptions. ndiff() documentation for argument default values and descriptions.
""" """
self._tabsize = tabsize self._tabsize = tabsize
...@@ -1655,13 +1655,13 @@ class HtmlDiff(object): ...@@ -1655,13 +1655,13 @@ class HtmlDiff(object):
the "next" link anchors before the next change (so click of the "next" link anchors before the next change (so click of
"next" link jumps to just before the change). "next" link jumps to just before the change).
""" """
return self._file_template % dict( return self._file_template % dict(
styles = self._styles, styles = self._styles,
legend = self._legend, legend = self._legend,
table = self.make_table(fromlines,tolines,fromdesc,todesc, table = self.make_table(fromlines,tolines,fromdesc,todesc,
context=context,numlines=numlines)) context=context,numlines=numlines))
def _tab_newline_replace(self,fromlines,tolines): def _tab_newline_replace(self,fromlines,tolines):
"""Returns from/to line lists with tabs expanded and newlines removed. """Returns from/to line lists with tabs expanded and newlines removed.
...@@ -1734,10 +1734,10 @@ class HtmlDiff(object): ...@@ -1734,10 +1734,10 @@ class HtmlDiff(object):
line1 = line1 + '\1' line1 = line1 + '\1'
line2 = '\0' + mark + line2 line2 = '\0' + mark + line2
# tack on first line onto the output list # tack on first line onto the output list
data_list.append((line_num,line1)) data_list.append((line_num,line1))
# use this routine again to wrap the remaining text # use this routine again to wrap the remaining text
self._split_line(data_list,'>',line2) self._split_line(data_list,'>',line2)
def _line_wrapper(self,diffs): def _line_wrapper(self,diffs):
...@@ -1776,7 +1776,7 @@ class HtmlDiff(object): ...@@ -1776,7 +1776,7 @@ class HtmlDiff(object):
""" """
fromlist,tolist,flaglist = [],[],[] fromlist,tolist,flaglist = [],[],[]
# pull from/to data and flags from mdiff style iterator # pull from/to data and flags from mdiff style iterator
for fromdata,todata,flag in diffs: for fromdata,todata,flag in diffs:
try: try:
# store HTML markup of the lines into the lists # store HTML markup of the lines into the lists
...@@ -1788,7 +1788,7 @@ class HtmlDiff(object): ...@@ -1788,7 +1788,7 @@ class HtmlDiff(object):
tolist.append(None) tolist.append(None)
flaglist.append(flag) flaglist.append(flag)
return fromlist,tolist,flaglist return fromlist,tolist,flaglist
def _format_line(self,side,flag,linenum,text): def _format_line(self,side,flag,linenum,text):
"""Returns HTML markup of "from" / "to" text lines """Returns HTML markup of "from" / "to" text lines
...@@ -1802,7 +1802,7 @@ class HtmlDiff(object): ...@@ -1802,7 +1802,7 @@ class HtmlDiff(object):
id = ' id="%s%s"' % (self._prefix[side],linenum) id = ' id="%s%s"' % (self._prefix[side],linenum)
except TypeError: except TypeError:
# handle blank lines where linenum is '>' or '' # handle blank lines where linenum is '>' or ''
id = '' id = ''
# replace those things that would get confused with HTML symbols # replace those things that would get confused with HTML symbols
text=text.replace("&","&amp;").replace(">","&gt;").replace("<","&lt;") text=text.replace("&","&amp;").replace(">","&gt;").replace("<","&lt;")
...@@ -1825,10 +1825,10 @@ class HtmlDiff(object): ...@@ -1825,10 +1825,10 @@ class HtmlDiff(object):
def _convert_flags(self,fromlist,tolist,flaglist,context,numlines): def _convert_flags(self,fromlist,tolist,flaglist,context,numlines):
"""Makes list of "next" links""" """Makes list of "next" links"""
# all anchor names will be generated using the unique "to" prefix # all anchor names will be generated using the unique "to" prefix
toprefix = self._prefix[1] toprefix = self._prefix[1]
# process change flags, generating middle column of next anchors/links # process change flags, generating middle column of next anchors/links
next_id = ['']*len(flaglist) next_id = ['']*len(flaglist)
next_href = ['']*len(flaglist) next_href = ['']*len(flaglist)
...@@ -1840,11 +1840,11 @@ class HtmlDiff(object): ...@@ -1840,11 +1840,11 @@ class HtmlDiff(object):
in_change = True in_change = True
last = i last = i
# at the beginning of a change, drop an anchor a few lines # at the beginning of a change, drop an anchor a few lines
# (the context lines) before the change for the previous # (the context lines) before the change for the previous
# link # link
i = max([0,i-numlines]) i = max([0,i-numlines])
next_id[i] = ' id="difflib_chg_%s_%d"' % (toprefix,num_chg) next_id[i] = ' id="difflib_chg_%s_%d"' % (toprefix,num_chg)
# at the beginning of a change, drop a link to the next # at the beginning of a change, drop a link to the next
# change # change
num_chg += 1 num_chg += 1
next_href[last] = '<a href="#difflib_chg_%s_%d">n</a>' % ( next_href[last] = '<a href="#difflib_chg_%s_%d">n</a>' % (
...@@ -1891,11 +1891,11 @@ class HtmlDiff(object): ...@@ -1891,11 +1891,11 @@ class HtmlDiff(object):
# make unique anchor prefixes so that multiple tables may exist # make unique anchor prefixes so that multiple tables may exist
# on the same page without conflict. # on the same page without conflict.
self._make_prefix() self._make_prefix()
# change tabs to spaces before it gets more difficult after we insert # change tabs to spaces before it gets more difficult after we insert
# markkup # markkup
fromlines,tolines = self._tab_newline_replace(fromlines,tolines) fromlines,tolines = self._tab_newline_replace(fromlines,tolines)
# create diffs iterator which generates side by side from/to data # create diffs iterator which generates side by side from/to data
if context: if context:
context_lines = numlines context_lines = numlines
...@@ -1907,7 +1907,7 @@ class HtmlDiff(object): ...@@ -1907,7 +1907,7 @@ class HtmlDiff(object):
# set up iterator to wrap lines that exceed desired width # set up iterator to wrap lines that exceed desired width
if self._wrapcolumn: if self._wrapcolumn:
diffs = self._line_wrapper(diffs) diffs = self._line_wrapper(diffs)
# collect up from/to lines and flags into lists (also format the lines) # collect up from/to lines and flags into lists (also format the lines)
fromlist,tolist,flaglist = self._collect_lines(diffs) fromlist,tolist,flaglist = self._collect_lines(diffs)
...@@ -1947,7 +1947,7 @@ class HtmlDiff(object): ...@@ -1947,7 +1947,7 @@ class HtmlDiff(object):
replace('\0^','<span class="diff_chg">'). \ replace('\0^','<span class="diff_chg">'). \
replace('\1','</span>'). \ replace('\1','</span>'). \
replace('\t','&nbsp;') replace('\t','&nbsp;')
del re del re
def restore(delta, which): def restore(delta, which):
......
...@@ -46,7 +46,7 @@ patch914575_to2 = """ ...@@ -46,7 +46,7 @@ patch914575_to2 = """
\tLine 2: preceeded by from:[sstt] to:[sssst] \tLine 2: preceeded by from:[sstt] to:[sssst]
Line 3: preceeded by from:[sstst] to:[ssssss] Line 3: preceeded by from:[sstst] to:[ssssss]
Line 4: has from:[sst] to:[sss] after : Line 4: has from:[sst] to:[sss] after :
Line 5: has from:[t] to:[ss] at end Line 5: has from:[t] to:[ss] at end
""" """
patch914575_from3 = """line 0 patch914575_from3 = """line 0
...@@ -54,9 +54,9 @@ patch914575_from3 = """line 0 ...@@ -54,9 +54,9 @@ patch914575_from3 = """line 0
line 1 line 1
line 2 line 2
line 3 line 3
line 4 changed line 4 changed
line 5 changed line 5 changed
line 6 changed line 6 changed
line 7 line 7
line 8 subtracted line 8 subtracted
line 9 line 9
...@@ -71,9 +71,9 @@ patch914575_to3 = """line 0 ...@@ -71,9 +71,9 @@ patch914575_to3 = """line 0
line 1 line 1
line 2 added line 2 added
line 3 line 3
line 4 chanGEd line 4 chanGEd
line 5a chanGed line 5a chanGed
line 6a changEd line 6a changEd
line 7 line 7
line 8 line 8
line 9 line 9
...@@ -102,21 +102,21 @@ class TestSFpatches(unittest.TestCase): ...@@ -102,21 +102,21 @@ class TestSFpatches(unittest.TestCase):
i = difflib.HtmlDiff() i = difflib.HtmlDiff()
j = difflib.HtmlDiff(tabsize=2) j = difflib.HtmlDiff(tabsize=2)
k = difflib.HtmlDiff(wrapcolumn=14) k = difflib.HtmlDiff(wrapcolumn=14)
full = i.make_file(f1a,t1a,'from','to',context=False,numlines=5) full = i.make_file(f1a,t1a,'from','to',context=False,numlines=5)
tables = '\n'.join( tables = '\n'.join(
[ [
'<h2>Context (first diff within numlines=5(default))</h2>', '<h2>Context (first diff within numlines=5(default))</h2>',
i.make_table(f1a,t1a,'from','to',context=True), i.make_table(f1a,t1a,'from','to',context=True),
'<h2>Context (first diff after numlines=5(default))</h2>', '<h2>Context (first diff after numlines=5(default))</h2>',
i.make_table(f1b,t1b,'from','to',context=True), i.make_table(f1b,t1b,'from','to',context=True),
'<h2>Context (numlines=6)</h2>', '<h2>Context (numlines=6)</h2>',
i.make_table(f1a,t1a,'from','to',context=True,numlines=6), i.make_table(f1a,t1a,'from','to',context=True,numlines=6),
'<h2>Context (numlines=0)</h2>', '<h2>Context (numlines=0)</h2>',
i.make_table(f1a,t1a,'from','to',context=True,numlines=0), i.make_table(f1a,t1a,'from','to',context=True,numlines=0),
'<h2>Same Context</h2>', '<h2>Same Context</h2>',
i.make_table(f1a,f1a,'from','to',context=True), i.make_table(f1a,f1a,'from','to',context=True),
'<h2>Same Full</h2>', '<h2>Same Full</h2>',
i.make_table(f1a,f1a,'from','to',context=False), i.make_table(f1a,f1a,'from','to',context=False),
'<h2>Empty Context</h2>', '<h2>Empty Context</h2>',
i.make_table([],[],'from','to',context=True), i.make_table([],[],'from','to',context=True),
...@@ -139,8 +139,8 @@ class TestSFpatches(unittest.TestCase): ...@@ -139,8 +139,8 @@ class TestSFpatches(unittest.TestCase):
#f.write(actual) #f.write(actual)
#f.close() #f.close()
expect = open(findfile('test_difflib_expect.html')).read() expect = open(findfile('test_difflib_expect.html')).read()
self.assertEqual(actual,expect) self.assertEqual(actual,expect)
Doctests = doctest.DocTestSuite(difflib) Doctests = doctest.DocTestSuite(difflib)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment