From 63916067ee74414f99c46dbf1480c894f097b916 Mon Sep 17 00:00:00 2001 From: yrrepy <100789850+yrrepy@users.noreply.github.com> Date: Tue, 16 Jan 2024 22:54:03 -0800 Subject: [PATCH] Use huge_tree=True in lxml parsing (#2791) Co-authored-by: Paul Romano --- openmc/geometry.py | 3 ++- openmc/material.py | 3 ++- openmc/model/model.py | 3 ++- openmc/plots.py | 3 ++- openmc/settings.py | 3 ++- openmc/tallies.py | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index 60f4a390d44..8815f2c8380 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -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) diff --git a/openmc/material.py b/openmc/material.py index 1f5496f15ea..d42c489aee0 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -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) diff --git a/openmc/model/model.py b/openmc/model/model.py index a60960b2bad..5194fec1daa 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -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() diff --git a/openmc/plots.py b/openmc/plots.py index b38b51a59c6..c73e3cdf73e 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -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) diff --git a/openmc/settings.py b/openmc/settings.py index 6486d1f2a8e..a6d273901e0 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -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) diff --git a/openmc/tallies.py b/openmc/tallies.py index b6cd4d13939..ddc5d68ee6c 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -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)