UtilitiesPython2/Py2SyntaxChecker.py

changeset 1465
3b459b88fcd4
parent 1308
2b602a1521e7
child 1509
c0b5e693b0eb
diff -r e4ec683781e4 -r 3b459b88fcd4 UtilitiesPython2/Py2SyntaxChecker.py
--- a/UtilitiesPython2/Py2SyntaxChecker.py	Mon Nov 21 20:06:36 2011 +0100
+++ b/UtilitiesPython2/Py2SyntaxChecker.py	Sat Nov 26 13:58:17 2011 +0100
@@ -45,19 +45,18 @@
         else:
             __builtin__.compile(codestring, file, 'exec')
     except SyntaxError, detail:
+        index = "0"
+        code = ""
+        error = ""
         lines = traceback.format_exception_only(SyntaxError, detail)
         match = re.match('\s*File "(.+)", line (\d+)',
             lines[0].replace('<string>', '%s' % file))
         if match is not None:
             fn, line = match.group(1, 2)
             if lines[1].startswith('SyntaxError:'):
-                code = ""
                 error = re.match('SyntaxError: (.+)', lines[1]).group(1)
-                index = "0"
             else:
                 code = re.match('(.+)', lines[1]).group(1)
-                error = ""
-                index = "0"
                 for seLine in lines[2:]:
                     if seLine.startswith('SyntaxError:'):
                         error = re.match('SyntaxError: (.+)', seLine).group(1)
@@ -66,11 +65,11 @@
         else:
             fn = detail.filename
             line = detail.lineno and detail.lineno or 1
-            code = ""
             error = detail.msg
         return (1, fn, line, index, code, error)
     except ValueError, detail:
         index = "0"
+        code = ""
         try:
             fn = detail.filename
             line = detail.lineno
@@ -79,15 +78,14 @@
             fn = file
             line = 1
             error = unicode(detail)
-        code = ""
         return (1, fn, line, index, code, error)
     except StandardError, detail:
         try:
             fn = detail.filename
             line = detail.lineno
+            index = "0"
             code = ""
             error = detail.msg
-            index = "0"
             return (1, fn, line, index, code, error)
         except:         # this catchall is intentional
             pass

eric ide

mercurial