Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
tabnanny.Whitespace Class Reference

List of all members.

Public Member Functions

def __init__
def longest_run_of_spaces
def indent_level
def equal
def not_equal_witness
def less
def not_less_witness

Public Attributes

 raw
 n
 nt
 norm
 is_simple

Detailed Description

Definition at line 132 of file tabnanny.py.


Constructor & Destructor Documentation

def tabnanny.Whitespace.__init__ (   self,
  ws 
)

Definition at line 155 of file tabnanny.py.

00155 
00156     def __init__(self, ws):
00157         self.raw  = ws
00158         S, T = Whitespace.S, Whitespace.T
00159         count = []
00160         b = n = nt = 0
00161         for ch in self.raw:
00162             if ch == S:
00163                 n = n + 1
00164                 b = b + 1
00165             elif ch == T:
00166                 n = n + 1
00167                 nt = nt + 1
00168                 if b >= len(count):
00169                     count = count + [0] * (b - len(count) + 1)
00170                 count[b] = count[b] + 1
00171                 b = 0
00172             else:
00173                 break
00174         self.n    = n
00175         self.nt   = nt
00176         self.norm = tuple(count), b
00177         self.is_simple = len(count) <= 1

Here is the caller graph for this function:


Member Function Documentation

def tabnanny.Whitespace.equal (   self,
  other 
)

Definition at line 207 of file tabnanny.py.

00207 
00208     def equal(self, other):
00209         return self.norm == other.norm

def tabnanny.Whitespace.indent_level (   self,
  tabsize 
)

Definition at line 184 of file tabnanny.py.

00184 
00185     def indent_level(self, tabsize):
00186         # count, il = self.norm
00187         # for i in range(len(count)):
00188         #    if count[i]:
00189         #        il = il + (i/tabsize + 1)*tabsize * count[i]
00190         # return il
00191 
00192         # quicker:
00193         # il = trailing + sum (i/ts + 1)*ts*count[i] =
00194         # trailing + ts * sum (i/ts + 1)*count[i] =
00195         # trailing + ts * sum i/ts*count[i] + count[i] =
00196         # trailing + ts * [(sum i/ts*count[i]) + (sum count[i])] =
00197         # trailing + ts * [(sum i/ts*count[i]) + num_tabs]
00198         # and note that i/ts*count[i] is 0 when i < ts
00199 
00200         count, trailing = self.norm
00201         il = 0
00202         for i in range(tabsize, len(count)):
00203             il = il + i/tabsize * count[i]
00204         return trailing + tabsize * (il + self.nt)

Here is the caller graph for this function:

def tabnanny.Whitespace.less (   self,
  other 
)

Definition at line 238 of file tabnanny.py.

00238 
00239     def less(self, other):
00240         if self.n >= other.n:
00241             return False
00242         if self.is_simple and other.is_simple:
00243             return self.nt <= other.nt
00244         n = max(self.longest_run_of_spaces(),
00245                 other.longest_run_of_spaces()) + 1
00246         # the self.n >= other.n test already did it for ts=1
00247         for ts in range(2, n+1):
00248             if self.indent_level(ts) >= other.indent_level(ts):
00249                 return False
00250         return True

Here is the call graph for this function:

Definition at line 180 of file tabnanny.py.

00180 
00181     def longest_run_of_spaces(self):
00182         count, trailing = self.norm
00183         return max(len(count)-1, trailing)

Here is the caller graph for this function:

def tabnanny.Whitespace.not_equal_witness (   self,
  other 
)

Definition at line 214 of file tabnanny.py.

00214 
00215     def not_equal_witness(self, other):
00216         n = max(self.longest_run_of_spaces(),
00217                 other.longest_run_of_spaces()) + 1
00218         a = []
00219         for ts in range(1, n+1):
00220             if self.indent_level(ts) != other.indent_level(ts):
00221                 a.append( (ts,
00222                            self.indent_level(ts),
00223                            other.indent_level(ts)) )
00224         return a

Here is the call graph for this function:

def tabnanny.Whitespace.not_less_witness (   self,
  other 
)

Definition at line 255 of file tabnanny.py.

00255 
00256     def not_less_witness(self, other):
00257         n = max(self.longest_run_of_spaces(),
00258                 other.longest_run_of_spaces()) + 1
00259         a = []
00260         for ts in range(1, n+1):
00261             if self.indent_level(ts) >= other.indent_level(ts):
00262                 a.append( (ts,
00263                            self.indent_level(ts),
00264                            other.indent_level(ts)) )
00265         return a

Here is the call graph for this function:


Member Data Documentation

Definition at line 176 of file tabnanny.py.

Definition at line 173 of file tabnanny.py.

Definition at line 175 of file tabnanny.py.

Definition at line 174 of file tabnanny.py.

Definition at line 156 of file tabnanny.py.


The documentation for this class was generated from the following file: