99-v Verbose. Print informative msgs; else no output.
1010
1111Change Python (.py) files to use 4-space indents and no hard tab characters.
12- Also trim excess whitespace from ends of lines, and empty lines at the ends
13- of files. Ensure the last line ends with a newline.
12+ Also trim excess spaces and tabs from ends of lines, and remove empty lines
13+ at the end of files. Also ensure the last line ends with a newline.
1414
1515Pass one or more file and/or directory paths. When a directory path, all
1616.py files within the directory will be examined, and, if the -r option is
@@ -108,6 +108,19 @@ def check(file):
108108 if verbose :
109109 print "unchanged."
110110
111+ def _rstrip (line , JUNK = '\n \t ' ):
112+ """Return line stripped of trailing spaces, tabs, newlines.
113+
114+ Note that line.rstrip() instead also strips sundry control characters,
115+ but at least one known Emacs user expects to keep junk like that, not
116+ mentioning Barry by name or anything <wink>.
117+ """
118+
119+ i = len (line )
120+ while i > 0 and line [i - 1 ] in JUNK :
121+ i -= 1
122+ return line [:i ]
123+
111124class Reindenter :
112125
113126 def __init__ (self , f ):
@@ -120,7 +133,7 @@ def __init__(self, f):
120133 # File lines, rstripped & tab-expanded. Dummy at start is so
121134 # that we can use tokenize's 1-based line numbering easily.
122135 # Note that a line is all-blank iff it's "\n".
123- self .lines = [line . rstrip ( ).expandtabs () + "\n "
136+ self .lines = [_rstrip ( line ).expandtabs () + "\n "
124137 for line in self .raw ]
125138 self .lines .insert (0 , None )
126139 self .index = 1 # index into self.lines of next line
0 commit comments