Utilities/__init__.py

changeset 1465
3b459b88fcd4
parent 1368
4489ee4feb59
child 1474
1eaec11a0078
--- 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

eric ide

mercurial