test invalid xml
This commit is contained in:
parent
81d30612e8
commit
f8959ef16f
@ -3,7 +3,7 @@ from os.path import join, isfile, basename, isdir
|
||||
from os import listdir
|
||||
#from io import BytesIO
|
||||
|
||||
from lxml.etree import DTD, parse, tostring # , XMLParser
|
||||
from lxml.etree import DTD, parse, tostring, XMLSyntaxError
|
||||
|
||||
from .i18n import _
|
||||
from .error import DictConsistencyError
|
||||
@ -34,10 +34,12 @@ class XMLReflector(object):
|
||||
|
||||
:returns: the root element tree object
|
||||
"""
|
||||
# document = parse(BytesIO(xmlfile), XMLParser(remove_blank_text=True))
|
||||
document = parse(xmlfile)
|
||||
try:
|
||||
document = parse(xmlfile)
|
||||
except XMLSyntaxError as err:
|
||||
raise DictConsistencyError(_(f'{xmlfile} is not an XML file: {err}'), 52)
|
||||
if not self.dtd.validate(document):
|
||||
raise DictConsistencyError(_(f'"{xmlfile}" not a valid xml file: {self.dtd.error_log.filter_from_errors()[0]}'), 43)
|
||||
raise DictConsistencyError(_(f'"{xmlfile}" not a valid XML file: {self.dtd.error_log.filter_from_errors()[0]}'), 43)
|
||||
return document.getroot()
|
||||
|
||||
def load_xml_from_folders(self, xmlfolders):
|
||||
|
7
tests/dictionaries/80invalid_dtd/00_base.xml
Normal file
7
tests/dictionaries/80invalid_dtd/00_base.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<services>
|
||||
<unknown>
|
||||
</unknown>
|
||||
</services>
|
||||
</rougail>
|
0
tests/dictionaries/80invalid_dtd/__init__.py
Normal file
0
tests/dictionaries/80invalid_dtd/__init__.py
Normal file
0
tests/dictionaries/80invalid_dtd/errno_43
Normal file
0
tests/dictionaries/80invalid_dtd/errno_43
Normal file
5
tests/dictionaries/80invalid_xml/00_base.xml
Normal file
5
tests/dictionaries/80invalid_xml/00_base.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<services/>
|
||||
</services>
|
||||
</rougail>
|
0
tests/dictionaries/80invalid_xml/__init__.py
Normal file
0
tests/dictionaries/80invalid_xml/__init__.py
Normal file
0
tests/dictionaries/80invalid_xml/errno_52
Normal file
0
tests/dictionaries/80invalid_xml/errno_52
Normal file
Loading…
Reference in New Issue
Block a user