UtilitiesPython2/Tabnanny.py

changeset 2998
95581102e03e
parent 2965
d133c7edd88a
child 3039
8dd0165d805d
equal deleted inserted replaced
2997:7f0ef975da9e 2998:95581102e03e
91 return self.line 91 return self.line
92 92
93 93
94 def check(filename, codestring): 94 def check(filename, codestring):
95 """ 95 """
96 Private function to check one Python source file for whitespace related problems. 96 Private function to check one Python source file for whitespace related
97 problems.
97 98
98 @param filename source filename (string) 99 @param filename source filename (string)
99 @param codestring source code (string) 100 @param codestring source code (string)
100 @return A tuple indicating status (True = an error was found), the 101 @return A tuple indicating status (True = an error was found), the
101 filename, the linenumber and the error message 102 filename, the linenumber and the error message
112 113
113 except tokenize.TokenError, msg: 114 except tokenize.TokenError, msg:
114 return (True, filename, "1", "Token Error: %s" % unicode(msg)) 115 return (True, filename, "1", "Token Error: %s" % unicode(msg))
115 116
116 except IndentationError, err: 117 except IndentationError, err:
117 return (True, filename, err.lineno, "Indentation Error: %s" % unicode(err.msg)) 118 return (True, filename, err.lineno,
119 "Indentation Error: %s" % unicode(err.msg))
118 120
119 except NannyNag, nag: 121 except NannyNag, nag:
120 badline = nag.get_lineno() 122 badline = nag.get_lineno()
121 line = nag.get_line() 123 line = nag.get_line()
122 return (True, filename, str(badline), line) 124 return (True, filename, str(badline), line)
222 224
223 # return true iff self.indent_level(t) == other.indent_level(t) 225 # return true iff self.indent_level(t) == other.indent_level(t)
224 # for all t >= 1 226 # for all t >= 1
225 def equal(self, other): 227 def equal(self, other):
226 """ 228 """
227 Method to compare the indentation levels of two Whitespace objects for equality. 229 Method to compare the indentation levels of two Whitespace objects for
230 equality.
228 231
229 @param other Whitespace object to compare against. 232 @param other Whitespace object to compare against.
230 @return True, if we compare equal against the other Whitespace object. 233 @return True, if we compare equal against the other Whitespace object.
231 """ 234 """
232 return self.norm == other.norm 235 return self.norm == other.norm
269 # M.num_tabs() <= N.num_tabs(). Proof is easy but kinda long-winded. 272 # M.num_tabs() <= N.num_tabs(). Proof is easy but kinda long-winded.
270 # XXXwrite that up. 273 # XXXwrite that up.
271 # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1. 274 # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1.
272 def less(self, other): 275 def less(self, other):
273 """ 276 """
274 Method to compare the indentation level against another Whitespace objects to 277 Method to compare the indentation level against another Whitespace
275 be smaller. 278 objects to be smaller.
276 279
277 @param other Whitespace object to compare against. 280 @param other Whitespace object to compare against.
278 @return True, if we compare less against the other Whitespace object. 281 @return True, if we compare less against the other Whitespace object.
279 """ 282 """
280 if self.n >= other.n: 283 if self.n >= other.n:
368 # equal to what's left at the top of the indents stack 371 # equal to what's left at the top of the indents stack
369 372
370 # Ouch! This assert triggers if the last line of the source 373 # Ouch! This assert triggers if the last line of the source
371 # is indented *and* lacks a newline -- then DEDENTs pop out 374 # is indented *and* lacks a newline -- then DEDENTs pop out
372 # of thin air. 375 # of thin air.
373 # assert check_equal # else no earlier NEWLINE, or an earlier INDENT 376 # assert check_equal # else no earlier NEWLINE, or an
377 # earlier INDENT
374 check_equal = 1 378 check_equal = 1
375 379
376 del indents[-1] 380 del indents[-1]
377 381
378 elif check_equal and type not in JUNK: 382 elif check_equal and type not in JUNK:

eric ide

mercurial