[GRASS-SVN] r65200 - grass/trunk/lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 8 20:31:24 PDT 2015


Author: wenzeslaus
Date: 2015-05-08 20:31:24 -0700 (Fri, 08 May 2015)
New Revision: 65200

Modified:
   grass/trunk/lib/python/script/task.py
Log:
pythonlib: more error for script.task.parse_interface

Trying to avoid any possible unhandled excpetion when parsing modules. This helps modules which are parsed on startup to construct menus (toolboxes).

Motivation is an the following reported (http://lists.osgeo.org/pipermail/grass-dev/2015-May/074999.html) error:
  ParseError: not well-formed (invalid token): line 17, column 19
which occured in parse_interface during _expandRuntimeModules in toolboxes.py


Modified: grass/trunk/lib/python/script/task.py
===================================================================
--- grass/trunk/lib/python/script/task.py	2015-05-09 02:53:07 UTC (rev 65199)
+++ grass/trunk/lib/python/script/task.py	2015-05-09 03:31:24 UTC (rev 65200)
@@ -24,6 +24,13 @@
     import xml.etree.ElementTree as etree
 except ImportError:
     import elementtree.ElementTree as etree # Python <= 2.4
+from xml.parsers import expat  # TODO: works for any Python?
+# Get the XML parsing exceptions to catch. The behavior chnaged with Python 2.7
+# and ElementTree 1.3.
+if hasattr(etree, 'ParseError'):
+    ETREE_EXCEPTIONS = (etree.ParseError, expat.ExpatError)
+else:
+    ETREE_EXCEPTIONS = (expat.ExpatError)
 
 from utils import decode, split
 from core import *
@@ -506,7 +513,11 @@
     :param parser:
     :param blackList:
     """
-    tree = etree.fromstring(get_interface_description(name))
+    try:
+        tree = etree.fromstring(get_interface_description(name))
+    except ETREE_EXCEPTIONS as error:
+        raise ScriptError(_("Cannot parse interface description of"
+            "<{name}> module: {error}").format(name=name, error=error))
     return parser(tree, blackList=blackList).get_task()
 
 



More information about the grass-commit mailing list