Thu, 31 Jul 2014 16:53:43 +0200
Possible exception on fixing code styles fixed (only Python2).
(grafted from ea909da895abc4674e988cf6f54ba5d260111493)
--- a/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Thu Jul 31 16:37:52 2014 +0200 +++ b/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py Thu Jul 31 16:53:43 2014 +0200 @@ -104,14 +104,6 @@ hangClosing, docType, errors, eol, encoding, backup = args stats = {} - # avoid 'Encoding declaration in unicode string' exception on Python2 - if sys.version_info[0] == 2: - if encoding == 'utf-8-bom': - enc = 'utf-8' - else: - enc = encoding - source = [line.encode(enc) for line in source] - # Don't check an empty file if source == []: return stats, [] @@ -125,6 +117,14 @@ fixer = None if not errors: + # avoid 'Encoding declaration in unicode string' exception on Python2 + if sys.version_info[0] == 2: + if encoding == 'utf-8-bom': + enc = 'utf-8' + else: + enc = encoding + source = [line.encode(enc) for line in source] + if includeMessages: select = [s.strip() for s in includeMessages.split(',') if s.strip()]
--- a/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py Thu Jul 31 16:37:52 2014 +0200 +++ b/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py Thu Jul 31 16:53:43 2014 +0200 @@ -7,6 +7,7 @@ Module implementing a class to fix certain code style issues. """ +from __future__ import unicode_literals try: # Python 2 from StringIO import StringIO # __IGNORE_EXCEPTION__ @@ -15,7 +16,6 @@ from io import StringIO # __IGNORE_WARNING__ import os import re -import sys import tokenize # CodeStyleCheckerDialog tries to import FixableCodeStyleIssues what fail under @@ -209,8 +209,8 @@ txt = "".join(self.__source) try: - if sys.version_info[0] == 3: - txt = txt.encode(encoding) + enc = 'utf-8' if encoding == 'utf-8-bom' else encoding + txt = txt.encode(enc) if encoding == 'utf-8-bom': txt = codecs.BOM_UTF8 + txt