Procházet zdrojové kódy

backport https://trac.osgeo.org/grass/changeset/65200 (more error for script.task.parse_interface)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@65662 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras před 9 roky
rodič
revize
999aa55a5b
1 změnil soubory, kde provedl 12 přidání a 1 odebrání
  1. 12 1
      lib/python/script/task.py

+ 12 - 1
lib/python/script/task.py

@@ -24,6 +24,13 @@ try:
     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
 from core import *
@@ -506,7 +513,11 @@ def parse_interface(name, parser=processTask, blackList=None):
     :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()