diff sat_frontends/jp/xml_tools.py @ 2804:710de41da2f2

jp (pubsub/node): new "import" command, to publish many nodes from an XML file
author Goffi <goffi@goffi.org>
date Fri, 15 Feb 2019 22:13:43 +0100
parents ff1b40823b07
children ab2696e34d29
line wrap: on
line diff
--- a/sat_frontends/jp/xml_tools.py	Fri Feb 15 22:13:43 2019 +0100
+++ b/sat_frontends/jp/xml_tools.py	Fri Feb 15 22:13:43 2019 +0100
@@ -20,11 +20,13 @@
 from sat.core.i18n import _
 from sat_frontends.jp.constants import Const as C
 
-def etreeParse(cmd, raw_xml):
+def etreeParse(cmd, raw_xml, reraise=False):
     """Import lxml and parse raw XML
 
     @param cmd(CommandBase): current command instance
     @param raw_xml(file, str): an XML bytestring, string or file-like object
+    @param reraise(bool): if True, re raise exception on parse error instead of doing a
+        parser.error (which terminate the execution)
     @return (tuple(etree.Element, module): parsed element, etree module
     """
     try:
@@ -42,6 +44,8 @@
         else:
             element = etree.parse(raw_xml).getroot()
     except Exception as e:
+        if reraise:
+            raise e
         cmd.parser.error(
             _(u"Can't parse the payload XML in input: {msg}").format(msg=e)
         )