88 |
87 |
89 @return The line of code (string) |
88 @return The line of code (string) |
90 """ |
89 """ |
91 return self.line |
90 return self.line |
92 |
91 |
93 def check(file): |
92 def check(file, text = ""): |
94 """ |
93 """ |
95 Private function to check one Python source file for whitespace related problems. |
94 Private function to check one Python source file for whitespace related problems. |
96 |
95 |
97 @param file source filename (string) |
96 @param file source filename (string) |
|
97 @param text source text (string) |
98 @return A tuple indicating status (True = an error was found), the |
98 @return A tuple indicating status (True = an error was found), the |
99 filename, the linenumber and the error message |
99 filename, the linenumber and the error message |
100 (boolean, string, string, string). The values are only |
100 (boolean, string, string, string). The values are only |
101 valid, if the status is True. |
101 valid, if the status is True. |
102 """ |
102 """ |
103 global indents, check_equal |
103 global indents, check_equal |
104 indents = [Whitespace("")] |
104 indents = [Whitespace("")] |
105 check_equal = 0 |
105 check_equal = 0 |
106 |
106 |
107 try: |
107 if not text: |
108 text = Utilities.readEncodedFile(file)[0] |
108 try: |
109 except (UnicodeError, IOError) as msg: |
109 text = Utilities.readEncodedFile(file)[0] |
110 return (True, file, "1", "Error: {0}".format(str(msg))) |
110 except (UnicodeError, IOError) as msg: |
111 |
111 return (True, file, "1", "Error: {0}".format(str(msg))) |
112 # convert eols |
112 |
113 text = Utilities.convertLineEnds(text, os.linesep) |
113 # convert eols |
|
114 text = Utilities.convertLineEnds(text, "\n") |
114 |
115 |
115 source = io.StringIO(text) |
116 source = io.StringIO(text) |
116 try: |
117 try: |
117 process_tokens(tokenize.generate_tokens(source.readline)) |
118 process_tokens(tokenize.generate_tokens(source.readline)) |
118 |
119 |