Skip to content

Commit

Permalink
defusedxml recover coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
xgodon committed May 14, 2019
1 parent 07620c1 commit 7bdbcdb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
10 changes: 5 additions & 5 deletions ssxtd/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down
30 changes: 24 additions & 6 deletions ssxtd/tests/test_malformed_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('''
<animals>
Expand Down Expand Up @@ -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()

0 comments on commit 7bdbcdb

Please sign in to comment.