[Python-checkins] CVS: python/dist/src/Lib compilerlike.py,1.1,1.2

Eric S. Raymond esr@users.sourceforge.net
2001年8月20日 06:16:32 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv20067/Lib
Modified Files:
	compilerlike.py 
Log Message:
Clean up some argument profiles, enrich the docstring.
Index: compilerlike.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/compilerlike.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** compilerlike.py	2001年08月18日 09:24:38	1.1
--- compilerlike.py	2001年08月20日 13:16:30	1.2
***************
*** 8,17 ****
 output file.
 
! This module provides framework and glue code to make such programs easy
! to write. You supply a function to massage the file data; depending
! on which entry point you use, it can take input and output file pointers,
! or it can take a string consisting of the entire file's data and return
! a replacement, or it can take in succession strings consisting of each
! of the file's lines and return a translated line for each.
 
 Argument files are transformed in left to right order in the argument list.
--- 8,28 ----
 output file.
 
! This module provides framework and glue code to make such programs
! easy to write. You supply a function to massage the file data. It
! always takes initial name and filename arguments; depending on which
! entry point you use, it can also take input and output file pointers,
! or it can take a string consisting of the entire file's data and
! return a replacement, or it can take in succession strings consisting
! of each of the file's lines and return a translated line for each.
! 
! The fourth, optional argument of each entry point is a name
! transformation function or name suffix string. If it is of string
! type, the shortest suffix of each filename beginning with the first
! character of the argument string is stripped off. If the first
! character of the argument does not occur in the filename, no suffix is
! removed. Then the name suffix argument is concatenated to the end of
! the stripped filename. (Thus, a name suffix argument of ".x" will
! cause the filenames foo.c and bar.d to be transformed to foo.x and
! bar.x respectively.)
 
 Argument files are transformed in left to right order in the argument list.
***************
*** 26,31 ****
 
 # Requires Python 2.
- from __future__ import nested_scopes
- 
 import sys, os, filecmp, traceback
 
--- 37,40 ----
***************
*** 33,37 ****
 "Filter stdin to stdout, or file arguments to renamed files."
 if not arguments:
! trans_data("stdin", sys.stdin, sys.stdout)
 else:
 for file in arguments:
--- 42,46 ----
 "Filter stdin to stdout, or file arguments to renamed files."
 if not arguments:
! trans_data(name, "stdin", sys.stdin, sys.stdout)
 else:
 for file in arguments:
***************
*** 44,48 ****
 outfp = open(tempfile, "w")
 try:
! trans_data(file, infp, outfp)
 except:
 os.remove(tempfile)
--- 53,57 ----
 outfp = open(tempfile, "w")
 try:
! trans_data(name, file, infp, outfp)
 except:
 os.remove(tempfile)
***************
*** 63,67 ****
 os.rename(tempfile, trans_filename(file))
 
! def line_by_line(name, infp, outfp, translate_line):
 "Hook to do line-by-line translation for filters."
 while 1:
--- 72,76 ----
 os.rename(tempfile, trans_filename(file))
 
! def line_by_line(name, file, infp, outfp, translate_line):
 "Hook to do line-by-line translation for filters."
 while 1:
***************
*** 70,74 ****
 break
 elif line:	# None returns are skipped
! outfp.write(translate_line(name, line))
 
 def linefilter(name, arguments, trans_data, trans_filename=None):
--- 79,83 ----
 break
 elif line:	# None returns are skipped
! outfp.write(translate_line(name, file, line))
 
 def linefilter(name, arguments, trans_data, trans_filename=None):
***************
*** 76,80 ****
 return filefilter(name,
 arguments,
! lambda name, infp, outfp: line_by_line(name, infp, outfp, trans_data),
 trans_filename)
 
--- 85,89 ----
 return filefilter(name,
 arguments,
! lambda name, file, infp, outfp: line_by_line(name, file, infp, outfp, trans_data),
 trans_filename)
 
***************
*** 82,86 ****
 "Read input sources entire and transform them in memory."
 if not arguments:
! sys.stdout.write(trans_data(name, sys.stdin.read()))
 else:
 for file in arguments:
--- 91,95 ----
 "Read input sources entire and transform them in memory."
 if not arguments:
! sys.stdout.write(trans_data(name, "stdin", sys.stdin.read()))
 else:
 for file in arguments:
***************
*** 95,99 ****
 return 1
 try:
! outdoc = trans_data(name, indoc)
 except:
 os.remove(tempfile)
--- 104,108 ----
 return 1
 try:
! outdoc = trans_data(name, file, indoc)
 except:
 os.remove(tempfile)
***************
*** 121,125 ****
 return name + ".out"
 
! def filefilter_test(name, infp, outfp):
 "Test hook for filefilter entry point -- put dashes before blank lines."
 while 1:
--- 130,134 ----
 return name + ".out"
 
! def filefilter_test(name, file, infp, outfp):
 "Test hook for filefilter entry point -- put dashes before blank lines."
 while 1:
***************
*** 131,139 ****
 outfp.write(line)
 
! def linefilter_test(name, data):
 "Test hook for linefilter entry point -- wrap lines in brackets."
 return "<" + data[:-1] + ">\n"
 
! def sponge_test(name, data):
 "Test hook for the sponge entry point -- reverse file lines."
 lines = data.split("\n")
--- 140,148 ----
 outfp.write(line)
 
! def linefilter_test(name, file, data):
 "Test hook for linefilter entry point -- wrap lines in brackets."
 return "<" + data[:-1] + ">\n"
 
! def sponge_test(name, file, data):
 "Test hook for the sponge entry point -- reverse file lines."
 lines = data.split("\n")

AltStyle によって変換されたページ (->オリジナル) /