Fixed a few quirks in Utilities and UtilitiesPython2.

Sat, 26 Nov 2011 13:58:17 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 26 Nov 2011 13:58:17 +0100
changeset 1465
3b459b88fcd4
parent 1464
e4ec683781e4
child 1467
2ff8100aa2f0

Fixed a few quirks in Utilities and UtilitiesPython2.

Utilities/__init__.py file | annotate | diff | comparison | revisions
UtilitiesPython2/Py2SyntaxChecker.py file | annotate | diff | comparison | revisions
--- a/Utilities/__init__.py	Mon Nov 21 20:06:36 2011 +0100
+++ b/Utilities/__init__.py	Sat Nov 26 13:58:17 2011 +0100
@@ -1183,19 +1183,18 @@
     except SyntaxError as detail:
         import traceback
         import re
+        index = "0"
+        code = ""
+        error = ""
         lines = traceback.format_exception_only(SyntaxError, detail)
         match = re.match('\s*File "(.+)", line (\d+)',
             lines[0].replace('<string>', '{0}'.format(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)
@@ -1204,29 +1203,27 @@
         else:
             fn = detail.filename
             line = detail.lineno and detail.lineno or 1
-            index = "0"
-            code = ""
             error = detail.msg
         return (True, fn, line, index, code, error)
     except ValueError as detail:
         index = "0"
+        code = ""
         try:
             fn = detail.filename
             line = detail.lineno
             error = detail.msg
         except AttributeError:
             fn = file
-            line = 1
+            line = "1"
             error = str(detail)
-        code = ""
         return (True, fn, line, index, code, error)
     except Exception as detail:
         try:
             fn = detail.filename
             line = detail.lineno
+            index = "0"
             code = ""
             error = detail.msg
-            index = "0"
             return (True, fn, line, index, code, error)
         except:         # this catchall is intentional
             pass
--- 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