summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorjblum2008-12-30 00:51:54 +0000
committerjblum2008-12-30 00:51:54 +0000
commit015c18afbcff894affb3ede7f39d781354087051 (patch)
tree6826f2d625f3d798af9d0100df8e6c6efcf81415 /grc
parent50b2df2ed93de8dbba3185714a3e07e7470e1229 (diff)
downloadgnuradio-015c18afbcff894affb3ede7f39d781354087051.tar.gz
gnuradio-015c18afbcff894affb3ede7f39d781354087051.tar.bz2
gnuradio-015c18afbcff894affb3ede7f39d781354087051.zip
error handling for dtd validation
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10177 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc')
-rw-r--r--grc/src/utils/ParseXML.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/grc/src/utils/ParseXML.py b/grc/src/utils/ParseXML.py
index 71f8c5279..d05b7b8b5 100644
--- a/grc/src/utils/ParseXML.py
+++ b/grc/src/utils/ParseXML.py
@@ -20,7 +20,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from lxml import etree
from .. utils import odict
-XMLSyntaxError = etree.XMLSyntaxError
+class XMLSyntaxError(Exception):
+ def __init__(self, error_log):
+ self._error_log = error_log
+ def __str__(self):
+ return '\n'.join(map(str, self._error_log.filter_from_errors()))
def validate_dtd(xml_file, dtd_file=None):
"""
@@ -29,16 +33,14 @@ def validate_dtd(xml_file, dtd_file=None):
@param dtd_file the optional dtd file
@throws Exception validation fails
"""
- if dtd_file:
- dtd = etree.DTD(dtd_file)
- xml = etree.parse(xml_file)
- if not dtd.validate(xml.getroot()):
- raise XMLSyntaxError, '\n'.join(map(str, dtd.error_log.filter_from_errors()))
- else:
- parser = etree.XMLParser(dtd_validation=True)
- xml = etree.parse(xml_file, parser=parser)
- if parser.error_log:
- raise XMLSyntaxError, '\n'.join(map(str, parser.error_log.filter_from_errors()))
+ #perform parsing, use dtd validation if dtd file is not specified
+ parser = etree.XMLParser(dtd_validation=not dtd_file)
+ xml = etree.parse(xml_file, parser=parser)
+ if parser.error_log: raise XMLSyntaxError(parser.error_log)
+ #perform dtd validation if the dtd file is specified
+ if not dtd_file: return
+ dtd = etree.DTD(dtd_file)
+ if not dtd.validate(xml.getroot()): raise XMLSyntaxError(dtd.error_log)
def from_file(xml_file):
"""