Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

changeset 6891
93f82da09f22
parent 6645
ad476851d7e0
equal deleted inserted replaced
6890:26c1042f2eec 6891:93f82da09f22
206 """ 206 """
207 import codecs 207 import codecs
208 208
209 if not self.__modified: 209 if not self.__modified:
210 # no need to write 210 # no need to write
211 return 211 return None
212 212
213 if self.__createBackup: 213 if self.__createBackup:
214 # create a backup file before writing any changes 214 # create a backup file before writing any changes
215 if os.path.islink(self.__filename): 215 if os.path.islink(self.__filename):
216 bfn = '{0}~'.format(os.path.realpath(self.__filename)) 216 bfn = '{0}~'.format(os.path.realpath(self.__filename))
237 with open(self.__filename, "wb") as fp: 237 with open(self.__filename, "wb") as fp:
238 fp.write(txt) 238 fp.write(txt)
239 except (IOError, UnicodeError) as err: 239 except (IOError, UnicodeError) as err:
240 # Could not save the file! Skipping it. Reason: {0} 240 # Could not save the file! Skipping it. Reason: {0}
241 return ("FWRITE_ERROR", (str(err),)) 241 return ("FWRITE_ERROR", (str(err),))
242 return 242
243 return None
243 244
244 def __codeMatch(self, code): 245 def __codeMatch(self, code):
245 """ 246 """
246 Private method to check, if the code should be fixed. 247 Private method to check, if the code should be fixed.
247 248
1952 @param line number of the line to retrieve (integer) 1953 @param line number of the line to retrieve (integer)
1953 @return fixed line (string) 1954 @return fixed line (string)
1954 """ 1955 """
1955 if line < len(self.after): 1956 if line < len(self.after):
1956 return self.after[line] 1957 return self.after[line]
1958
1959 return ""
1957 1960
1958 def getline(self): 1961 def getline(self):
1959 """ 1962 """
1960 Public method to get a line of text for tokenize. 1963 Public method to get a line of text for tokenize.
1961 1964
2104 """ 2107 """
2105 # What follows is an adjusted version of 2108 # What follows is an adjusted version of
2106 # pycodestyle.py:continuation_line_indentation. All of the comments 2109 # pycodestyle.py:continuation_line_indentation. All of the comments
2107 # have been stripped and the 'yield' statements replaced with 'pass'. 2110 # have been stripped and the 'yield' statements replaced with 'pass'.
2108 if not self.tokens: 2111 if not self.tokens:
2109 return 2112 return []
2110 2113
2111 first_row = self.tokens[0][2][0] 2114 first_row = self.tokens[0][2][0]
2112 nrows = 1 + self.tokens[-1][2][0] - first_row 2115 nrows = 1 + self.tokens[-1][2][0] - first_row
2113 2116
2114 # here are the return values 2117 # here are the return values

eric ide

mercurial