From ad81d7a8f1c55bd244f3b57b0922df187ce09126 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Wed, 29 Nov 2023 11:03:49 -0600 Subject: [PATCH] Use yaml.safe_dump or NumpyToNativeDumper We want to make sure that we write out safe yaml files (that don't require an unsafe_load to load them). So always use `yaml.safe_dump()` or the `NumpyToNativeDumper` in HEXRD. Signed-off-by: Patrick Avery --- hexrdgui/hexrd_config.py | 3 ++- hexrdgui/image_file_manager.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hexrdgui/hexrd_config.py b/hexrdgui/hexrd_config.py index b498cbb36..777341703 100644 --- a/hexrdgui/hexrd_config.py +++ b/hexrdgui/hexrd_config.py @@ -16,6 +16,7 @@ from hexrd.instrument import HEDMInstrument from hexrd.material import load_materials_hdf5, save_materials_hdf5, Material from hexrd.rotations import RotMatEuler +from hexrd.utils.yaml import NumpyToNativeDumper from hexrd.valunits import valWUnit from hexrdgui import constants @@ -1154,7 +1155,7 @@ def recursive_key_check(d, c): cfg['working_dir'] = '.' with open(output_file, 'w') as f: - yaml.dump(cfg, f) + yaml.dump(cfg, f, Dumper=NumpyToNativeDumper) def create_internal_config(self, cur_config): if not self.has_status(cur_config): diff --git a/hexrdgui/image_file_manager.py b/hexrdgui/image_file_manager.py index de9073143..41edd9621 100644 --- a/hexrdgui/image_file_manager.py +++ b/hexrdgui/image_file_manager.py @@ -99,7 +99,7 @@ def open_file(self, f, options=None): input_dict['meta'] = {} temp = tempfile.NamedTemporaryFile(delete=False) try: - data = yaml.dump(input_dict).encode('utf-8') + data = yaml.safe_dump(input_dict).encode('utf-8') temp.write(data) temp.close() ims = imageseries.open(temp.name, 'image-files') @@ -129,7 +129,7 @@ def open_directory(self, d, files=None, options=None): input_dict['meta'] = {} temp = tempfile.NamedTemporaryFile(delete=False) try: - data = yaml.dump(input_dict).encode('utf-8') + data = yaml.safe_dump(input_dict).encode('utf-8') temp.write(data) temp.close() ims = imageseries.open(temp.name, 'image-files')