UtilitiesPython2/Tabnanny.py

changeset 945
8cd4d08fa9f6
parent 805
83ca4d1ff648
child 2965
d133c7edd88a
--- a/UtilitiesPython2/Tabnanny.py	Fri Mar 11 08:55:14 2011 +0100
+++ b/UtilitiesPython2/Tabnanny.py	Fri Mar 11 16:51:57 2011 +0100
@@ -48,6 +48,7 @@
 
 __all__ = ["check", "NannyNag", "process_tokens"]
 
+
 class NannyNag(Exception):
     """
     Raised by tokeneater() if detecting an ambiguous indent.
@@ -87,6 +88,7 @@
         """
         return self.line
 
+
 def check(filename, codestring):
     """
     Private function to check one Python source file for whitespace related problems.
@@ -122,6 +124,7 @@
     
     return (False, None, None, None)
 
+
 class Whitespace(object):
     """
     Class implementing the whitespace checker.
@@ -154,7 +157,7 @@
         
         @param ws The string to be checked.
         """
-        self.raw  = ws
+        self.raw = ws
         S, T = Whitespace.S, Whitespace.T
         count = []
         b = n = nt = 0
@@ -171,8 +174,8 @@
                 b = 0
             else:
                 break
-        self.n    = n
-        self.nt   = nt
+        self.n = n
+        self.nt = nt
         self.norm = tuple(count), b
         self.is_simple = len(count) <= 1
 
@@ -186,7 +189,7 @@
             preceding a tab)
         """
         count, trailing = self.norm
-        return max(len(count)-1, trailing)
+        return max(len(count) - 1, trailing)
 
     def indent_level(self, tabsize):
         """
@@ -212,7 +215,7 @@
         count, trailing = self.norm
         il = 0
         for i in range(tabsize, len(count)):
-            il = il + i/tabsize * count[i]
+            il = il + i / tabsize * count[i]
         return trailing + tabsize * (il + self.nt)
 
     # return true iff self.indent_level(t) == other.indent_level(t)
@@ -244,11 +247,11 @@
         n = max(self.longest_run_of_spaces(),
                 other.longest_run_of_spaces()) + 1
         a = []
-        for ts in range(1, n+1):
+        for ts in range(1, n + 1):
             if self.indent_level(ts) != other.indent_level(ts):
-                a.append( (ts,
+                a.append((ts,
                            self.indent_level(ts),
-                           other.indent_level(ts)) )
+                           other.indent_level(ts)))
         return a
 
     # Return True iff self.indent_level(t) < other.indent_level(t)
@@ -266,7 +269,7 @@
     # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1.
     def less(self, other):
         """
-        Method to compare the indentation level against another Whitespace objects to 
+        Method to compare the indentation level against another Whitespace objects to
         be smaller.
         
         @param other Whitespace object to compare against.
@@ -279,7 +282,7 @@
         n = max(self.longest_run_of_spaces(),
                 other.longest_run_of_spaces()) + 1
         # the self.n >= other.n test already did it for ts=1
-        for ts in range(2, n+1):
+        for ts in range(2, n + 1):
             if self.indent_level(ts) >= other.indent_level(ts):
                 return False
         return True
@@ -302,13 +305,14 @@
         n = max(self.longest_run_of_spaces(),
                 other.longest_run_of_spaces()) + 1
         a = []
-        for ts in range(1, n+1):
+        for ts in range(1, n + 1):
             if self.indent_level(ts) >= other.indent_level(ts):
-                a.append( (ts,
+                a.append((ts,
                            self.indent_level(ts),
-                           other.indent_level(ts)) )
+                           other.indent_level(ts)))
         return a
 
+
 def format_witnesses(w):
     """
     Function to format the witnesses as a readable string.
@@ -322,6 +326,7 @@
         prefix = prefix + "s"
     return prefix + " " + ', '.join(firsts)
 
+
 def process_tokens(tokens):
     """
     Function processing all tokens generated by a tokenizer run.

eric ide

mercurial