diff --git reindent.py reindent.py index 4a916ea..68f7c72 100755 --- a/Tools/scripts/reindent.py +++ b/Tools/scripts/reindent.py @@ -45,6 +45,7 @@ __version__ = "1" import tokenize import os +import re import shutil import sys @@ -209,6 +210,8 @@ class Reindenter: have2want = {} # Program after transformation. after = self.after = [] + # Regular expression to detect a tripple quote + triple_re = re.compile(tokenize.Triple) # Copy over initial empty lines -- there's nothing to do until # we see a line with *something* on it. i = stats[0][0] @@ -254,12 +257,21 @@ class Reindenter: if diff == 0 or have == 0: after.extend(lines[thisstmt:nextstmt]) else: + inside_triple = False + changed_triple = False for line in lines[thisstmt:nextstmt]: if diff > 0: - if line == "\n": + if not inside_triple and triple_re.search(line): + inside_triple = True + changed_triple = True + if line == "\n" or inside_triple: after.append(line) else: after.append(" " * diff + line) + if (inside_triple and triple_re.search(line) and + not changed_triple): + inside_triple = False + changed_triple = False else: remove = min(getlspace(line), -diff) after.append(line[remove:])