cpython: 8777e59a99bd (original) (raw)
--- a/Doc/library/difflib.rst
+++ b/Doc/library/difflib.rst
@@ -743,65 +743,4 @@ This example shows how to use difflib to
It is also contained in the Python source distribution, as
:file:Tools/scripts/diff.py
.
-.. testcode::
-
- """ Command line interface to difflib.py providing diffs in four formats: -
- """ -
- import sys, os, time, difflib, optparse -
- def main():
# Configure the option parser[](#l1.21)
usage = "usage: %prog [options] fromfile tofile"[](#l1.22)
parser = optparse.OptionParser(usage)[](#l1.23)
parser.add_option("-c", action="store_true", default=False,[](#l1.24)
help='Produce a context format diff (default)')[](#l1.25)
parser.add_option("-u", action="store_true", default=False,[](#l1.26)
help='Produce a unified format diff')[](#l1.27)
hlp = 'Produce HTML side by side diff (can use -c and -l in conjunction)'[](#l1.28)
parser.add_option("-m", action="store_true", default=False, help=hlp)[](#l1.29)
parser.add_option("-n", action="store_true", default=False,[](#l1.30)
help='Produce a ndiff format diff')[](#l1.31)
parser.add_option("-l", "--lines", type="int", default=3,[](#l1.32)
help='Set number of context lines (default 3)')[](#l1.33)
(options, args) = parser.parse_args()[](#l1.34)
if len(args) == 0:[](#l1.36)
parser.print_help()[](#l1.37)
sys.exit(1)[](#l1.38)
if len(args) != 2:[](#l1.39)
parser.error("need to specify both a fromfile and tofile")[](#l1.40)
n = options.lines[](#l1.42)
fromfile, tofile = args # as specified in the usage string[](#l1.43)
# we're passing these as arguments to the diff function[](#l1.45)
fromdate = time.ctime(os.stat(fromfile).st_mtime)[](#l1.46)
todate = time.ctime(os.stat(tofile).st_mtime)[](#l1.47)
with open(fromfile) as fromf, open(tofile) as tof:[](#l1.48)
fromlines, tolines = list(fromf), list(tof)[](#l1.49)
if options.u:[](#l1.51)
diff = difflib.unified_diff(fromlines, tolines, fromfile, tofile,[](#l1.52)
fromdate, todate, n=n)[](#l1.53)
elif options.n:[](#l1.54)
diff = difflib.ndiff(fromlines, tolines)[](#l1.55)
elif options.m:[](#l1.56)
diff = difflib.HtmlDiff().make_file(fromlines, tolines, fromfile,[](#l1.57)
tofile, context=options.c,[](#l1.58)
numlines=n)[](#l1.59)
else:[](#l1.60)
diff = difflib.context_diff(fromlines, tolines, fromfile, tofile,[](#l1.61)
fromdate, todate, n=n)[](#l1.62)
# we're using writelines because diff is a generator[](#l1.64)
sys.stdout.writelines(diff)[](#l1.65)