Plugins/CheckerPlugins/Tabnanny/Tabnanny.py

changeset 793
cd183f89874b
parent 415
59a0f9e90768
child 830
6caa4436dee2
equal deleted inserted replaced
791:9ec2ac20e54e 793:cd183f89874b
38 # Mofifications copyright (c) 2003 Detlev Offenbach <detlev@die-offenbachs.de> 38 # Mofifications copyright (c) 2003 Detlev Offenbach <detlev@die-offenbachs.de>
39 # 39 #
40 40
41 __version__ = "6_eric" 41 __version__ = "6_eric"
42 42
43 import os
44 import tokenize 43 import tokenize
45 import io 44 import io
46 45
47 import Utilities 46 import Utilities
48 47
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

eric ide

mercurial