209 bfn = '{0}~'.format(os.path.realpath(self.__filename)) |
209 bfn = '{0}~'.format(os.path.realpath(self.__filename)) |
210 else: |
210 else: |
211 bfn = '{0}~'.format(self.__filename) |
211 bfn = '{0}~'.format(self.__filename) |
212 try: |
212 try: |
213 os.remove(bfn) |
213 os.remove(bfn) |
214 except EnvironmentError: |
214 except OSError: |
215 # if there was an error, ignore it |
215 # if there was an error, ignore it |
216 pass |
216 pass |
217 try: |
217 try: |
218 os.rename(self.__filename, bfn) |
218 os.rename(self.__filename, bfn) |
219 except EnvironmentError: |
219 except OSError: |
220 # if there was an error, ignore it |
220 # if there was an error, ignore it |
221 pass |
221 pass |
222 |
222 |
223 txt = "".join(self.__source) |
223 txt = "".join(self.__source) |
224 try: |
224 try: |
227 if encoding == 'utf-8-bom': |
227 if encoding == 'utf-8-bom': |
228 txt = codecs.BOM_UTF8 + txt |
228 txt = codecs.BOM_UTF8 + txt |
229 |
229 |
230 with open(self.__filename, "wb") as fp: |
230 with open(self.__filename, "wb") as fp: |
231 fp.write(txt) |
231 fp.write(txt) |
232 except (IOError, UnicodeError) as err: |
232 except (OSError, UnicodeError) as err: |
233 # Could not save the file! Skipping it. Reason: {0} |
233 # Could not save the file! Skipping it. Reason: {0} |
234 return ("FIXWRITE_ERROR", [str(err)]) |
234 return ("FIXWRITE_ERROR", [str(err)]) |
235 |
235 |
236 return None |
236 return None |
237 |
237 |