diff --git a/ssxtd/parsers.py b/ssxtd/parsers.py index e16e516..e0420b9 100644 --- a/ssxtd/parsers.py +++ b/ssxtd/parsers.py @@ -138,14 +138,14 @@ def xml_parse(my_file, depth=2, compression=None, value_processor=None, object_p try: import defusedxml.ElementTree as DET - def dxml_iterparse(my_file, depth=2, compression=None, value_processor=None, object_processor=None, trim_spaces=False, del_empty=True, cleanup_namespaces=True, verbose=False): + def dxml_iterparse(my_file, depth=2, compression=None, value_processor=None, object_processor=None, trim_spaces=False, del_empty=True, cleanup_namespaces=True, verbose=False, recover=False): pm = DXML_IterParser_Manager(my_file=my_file, depth=depth, compression=compression, value_processor=value_processor, - object_processor=object_processor, trim_spaces=trim_spaces, del_empty=del_empty, cleanup_namespaces=cleanup_namespaces, verbose=verbose) + object_processor=object_processor, trim_spaces=trim_spaces, del_empty=del_empty, cleanup_namespaces=cleanup_namespaces, verbose=verbose, recover=recover) yield from pm.run() def dxml_parse(my_file, depth=2, compression=None, value_processor=None, object_processor=None, trim_spaces=False, del_empty=True, cleanup_namespaces=True, verbose=False, recover=False): pm = DXML_SimpleParser_Manager(my_file=my_file, depth=depth, compression=compression, value_processor=value_processor, - object_processor=object_processor, trim_spaces=trim_spaces, del_empty=del_empty, cleanup_namespaces=cleanup_namespaces, verbose=verbose) + object_processor=object_processor, trim_spaces=trim_spaces, del_empty=del_empty, cleanup_namespaces=cleanup_namespaces, verbose=verbose, recover=recover) yield from pm.run() except: @@ -375,9 +375,9 @@ def __init__(self, my_file, depth=2, compression=None, value_processor=None, obj class DXML_IterParser_Manager (IterParser_Manager): - def __init__(self, my_file, depth=2, compression=None, value_processor=None, object_processor=None, trim_spaces=False, del_empty=True, cleanup_namespaces=True, verbose=False): + def __init__(self, my_file, depth=2, compression=None, value_processor=None, object_processor=None, trim_spaces=False, del_empty=True, cleanup_namespaces=True, verbose=False, recover=False): super().__init__(my_file=my_file, depth=depth, compression=compression, value_processor=value_processor, - object_processor=object_processor, trim_spaces=trim_spaces, del_empty=del_empty, cleanup_namespaces=cleanup_namespaces, verbose=verbose) + object_processor=object_processor, trim_spaces=trim_spaces, del_empty=del_empty, cleanup_namespaces=cleanup_namespaces, verbose=verbose, recover=recover) self.lib = DET diff --git a/ssxtd/tests/test_malformed_xml.py b/ssxtd/tests/test_malformed_xml.py index e18f4e5..1720733 100644 --- a/ssxtd/tests/test_malformed_xml.py +++ b/ssxtd/tests/test_malformed_xml.py @@ -11,30 +11,37 @@ # LXML - def test_lxml_parse(): f1.seek(0) d = next(parsers.lxml_parse(f1, depth=my_depth, compression=None, recover=True, trim_spaces=True)) assert d == {'i': 'John'} - def test_lxml_iterparse(): f1.seek(0) d = next(parsers.lxml_iterparse(f1, depth=my_depth, compression=None, recover=True, trim_spaces=True)) assert d == {'i': 'John'} -# XML - +# XML def test_xml_parse(): f1.seek(0) d = next(parsers.xml_parse(f1, depth=my_depth, compression=None, recover=True)) assert d == {'i': 'John'} - def test_xml_iterparse(): f1.seek(0) d = next(parsers.xml_iterparse(f1, depth=my_depth, compression=None, recover=True)) - print(d) + assert d == {'i': 'John'} + +# DEFUSEDXML +def test_dxml_parse(): + f1.seek(0) + d = next(parsers.xml_parse(f1, depth=my_depth, compression=None, recover=True)) + assert d == {'i': 'John'} + +def test_dxml_iterparse(): + f1.seek(0) + d = next(parsers.xml_iterparse(f1, depth=my_depth, compression=None, recover=True)) + assert d == {'i': 'John'} f2 = BytesIO(''' @@ -70,4 +77,15 @@ def test_xml_iterparse_2(): d = next(parsers.xml_iterparse(f2, depth=my_depth, compression=None, recover=True, trim_spaces=True )) assert d == {'i': 'John'} +# DEFUSEDXML +def test_dxml_parse_2(): + f1.seek(0) + d = next(parsers.xml_parse(f2, depth=my_depth, compression=None, recover=True)) + assert d == {'i': 'John'} + +def test_dxml_iterparse_2(): + f1.seek(0) + d = next(parsers.xml_iterparse(f2, depth=my_depth, compression=None, recover=True)) + assert d == {'i': 'John'} + test_xml_iterparse() \ No newline at end of file