Fixed an issue in the documentation style checker related to Python2 source files.

Fri, 06 Nov 2015 11:20:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 06 Nov 2015 11:20:12 +0100
changeset 4547
7e0cb381dcbc
parent 4545
436736340877
child 4549
ab49cb7b400e

Fixed an issue in the documentation style checker related to Python2 source files.

Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py file | annotate | diff | comparison | revisions
--- a/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py	Wed Nov 04 16:45:07 2015 +0100
+++ b/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py	Fri Nov 06 11:20:12 2015 +0100
@@ -42,7 +42,11 @@
         @param startLine line number the context starts in the source (integer)
         @param contextType type of the context object (string)
         """
-        if isinstance(source, str):
+        if sys.version_info[0] == 2:
+            stringTypes = (str, unicode)        # __IGNORE_WARNING__
+        else:
+            stringTypes = str
+        if isinstance(source, stringTypes):
             self.__source = source.splitlines(True)
         else:
             self.__source = source[:]
@@ -330,9 +334,15 @@
             # don't do anything, if no codes were selected
             return
         
+        source = "".join(self.__source)
+        # Check type for py2: if not str it's unicode
+        if sys.version_info[0] == 2:
+            try:
+                source = source.encode('utf-8')
+            except UnicodeError:
+                pass
         try:
-            compile(''.join(self.__source), self.__filename, 'exec',
-                    ast.PyCF_ONLY_AST)
+            compile(source, self.__filename, 'exec', ast.PyCF_ONLY_AST)
         except (SyntaxError, TypeError):
             self.__reportInvalidSyntax()
             return

eric ide

mercurial