From ba001a0b676f640b3a11dea48b2a13d9fc0be746 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Thu, 4 Oct 2001 19:44:10 +0000 Subject: 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. --- Tools/scripts/reindent.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'Tools') diff --git a/Tools/scripts/reindent.py b/Tools/scripts/reindent.py index 4b742a8c42a..e646aed9c3c 100644 --- a/Tools/scripts/reindent.py +++ b/Tools/scripts/reindent.py @@ -9,8 +9,8 @@ -v Verbose. Print informative msgs; else no output. 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. +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 .py files within the directory will be examined, and, if the -r option is @@ -108,6 +108,19 @@ def check(file): if verbose: 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 . + """ + + i = len(line) + while i > 0 and line[i-1] in JUNK: + i -= 1 + return line[:i] + class Reindenter: def __init__(self, f): @@ -120,7 +133,7 @@ def __init__(self, f): # File lines, rstripped & tab-expanded. Dummy at start is so # 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" + self.lines = [_rstrip(line).expandtabs() + "\n" for line in self.raw] self.lines.insert(0, None) self.index = 1 # index into self.lines of next line -- cgit v1.2.3-65-gdbad