Skip to content

Commit

Permalink
Use huge_tree=True in lxml parsing (#2791)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
yrrepy and paulromano authored Jan 17, 2024
1 parent d7d2230 commit 6391606
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion openmc/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ def from_xml(
if isinstance(materials, (str, os.PathLike)):
materials = openmc.Materials.from_xml(materials)

tree = ET.parse(path)
parser = ET.XMLParser(huge_tree=True)
tree = ET.parse(path, parser=parser)
root = tree.getroot()

return cls.from_xml_element(root, materials)
Expand Down
3 changes: 2 additions & 1 deletion openmc/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,8 @@ def from_xml(cls, path: PathLike = 'materials.xml') -> Materials:
Materials collection
"""
tree = ET.parse(path)
parser = ET.XMLParser(huge_tree=True)
tree = ET.parse(path, parser=parser)
root = tree.getroot()

return cls.from_xml_element(root)
3 changes: 2 additions & 1 deletion openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def from_model_xml(cls, path='model.xml'):
path : str or PathLike
Path to model.xml file
"""
tree = ET.parse(path)
parser = ET.XMLParser(huge_tree=True)
tree = ET.parse(path, parser=parser)
root = tree.getroot()

model = cls()
Expand Down
3 changes: 2 additions & 1 deletion openmc/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,7 @@ def from_xml(cls, path='plots.xml'):
Plots collection
"""
tree = ET.parse(path)
parser = ET.XMLParser(huge_tree=True)
tree = ET.parse(path, parser=parser)
root = tree.getroot()
return cls.from_xml_element(root)
3 changes: 2 additions & 1 deletion openmc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,8 @@ def from_xml(cls, path: PathLike = 'settings.xml'):
Settings object
"""
tree = ET.parse(path)
parser = ET.XMLParser(huge_tree=True)
tree = ET.parse(path, parser=parser)
root = tree.getroot()
meshes = _read_meshes(root)
return cls.from_xml_element(root, meshes)
3 changes: 2 additions & 1 deletion openmc/tallies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3304,6 +3304,7 @@ def from_xml(cls, path='tallies.xml'):
Tallies object
"""
tree = ET.parse(path)
parser = ET.XMLParser(huge_tree=True)
tree = ET.parse(path, parser=parser)
root = tree.getroot()
return cls.from_xml_element(root)

0 comments on commit 6391606

Please sign in to comment.