[Python-checkins] CVS: python/dist/src/Tools/scripts reindent.py,1.1,1.2

Tim Peters tim_one@users.sourceforge.net
2001年10月04日 12:44:12 -0700


Update of /cvsroot/python/python/dist/src/Tools/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv12078/python/Tools/scripts
Modified Files:
	reindent.py 
Log Message:
Changed the reindenter to strip only trailing spaces and tabs from lines,
not other control characters string.rstrip() got rid of. This caters to
the \f thingies Barry likes putting in Python source files.
Index: reindent.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/reindent.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** reindent.py	2000年10月05日 03:48:38	1.1
--- reindent.py	2001年10月04日 19:44:10	1.2
***************
*** 10,15 ****
 
 Change Python (.py) files to use 4-space indents and no hard tab characters.
! Also trim excess whitespace from ends of lines, and empty lines at the ends
! of files. Ensure the last line ends with a newline.
 
 Pass one or more file and/or directory paths. When a directory path, all
--- 10,15 ----
 
 Change Python (.py) files to use 4-space indents and no hard tab characters.
! Also trim excess spaces and tabs from ends of lines, and remove empty lines
! at the end of files. Also ensure the last line ends with a newline.
 
 Pass one or more file and/or directory paths. When a directory path, all
***************
*** 109,112 ****
--- 109,125 ----
 print "unchanged."
 
+ def _rstrip(line, JUNK='\n \t'):
+ """Return line stripped of trailing spaces, tabs, newlines.
+ 
+ Note that line.rstrip() instead also strips sundry control characters,
+ but at least one known Emacs user expects to keep junk like that, not
+ mentioning Barry by name or anything <wink>.
+ """
+ 
+ i = len(line)
+ while i > 0 and line[i-1] in JUNK:
+ i -= 1
+ return line[:i]
+ 
 class Reindenter:
 
***************
*** 121,125 ****
 # that we can use tokenize's 1-based line numbering easily.
 # Note that a line is all-blank iff it's "\n".
! self.lines = [line.rstrip().expandtabs() + "\n"
 for line in self.raw]
 self.lines.insert(0, None)
--- 134,138 ----
 # that we can use tokenize's 1-based line numbering easily.
 # Note that a line is all-blank iff it's "\n".
! self.lines = [_rstrip(line).expandtabs() + "\n"
 for line in self.raw]
 self.lines.insert(0, None)

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