5 |
5 |
6 """ |
6 """ |
7 Module implementing a class to fix certain code style issues. |
7 Module implementing a class to fix certain code style issues. |
8 """ |
8 """ |
9 |
9 |
|
10 from __future__ import unicode_literals |
10 try: |
11 try: |
11 # Python 2 |
12 # Python 2 |
12 from StringIO import StringIO # __IGNORE_EXCEPTION__ |
13 from StringIO import StringIO # __IGNORE_EXCEPTION__ |
13 except ImportError: |
14 except ImportError: |
14 # Python 3 |
15 # Python 3 |
15 from io import StringIO # __IGNORE_WARNING__ |
16 from io import StringIO # __IGNORE_WARNING__ |
16 import os |
17 import os |
17 import re |
18 import re |
18 import sys |
|
19 import tokenize |
19 import tokenize |
20 |
20 |
21 # CodeStyleCheckerDialog tries to import FixableCodeStyleIssues what fail under |
21 # CodeStyleCheckerDialog tries to import FixableCodeStyleIssues what fail under |
22 # Python3. So ignore it. |
22 # Python3. So ignore it. |
23 try: |
23 try: |
207 # if there was an error, ignore it |
207 # if there was an error, ignore it |
208 pass |
208 pass |
209 |
209 |
210 txt = "".join(self.__source) |
210 txt = "".join(self.__source) |
211 try: |
211 try: |
212 if sys.version_info[0] == 3: |
212 enc = 'utf-8' if encoding == 'utf-8-bom' else encoding |
213 txt = txt.encode(encoding) |
213 txt = txt.encode(enc) |
214 if encoding == 'utf-8-bom': |
214 if encoding == 'utf-8-bom': |
215 txt = codecs.BOM_UTF8 + txt |
215 txt = codecs.BOM_UTF8 + txt |
216 |
216 |
217 with open(self.__filename, "wb") as fp: |
217 with open(self.__filename, "wb") as fp: |
218 fp.write(txt) |
218 fp.write(txt) |