Skip to content

Commit

Permalink
Use yaml.safe_dump or NumpyToNativeDumper
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
psavery committed Nov 29, 2023
1 parent 2ea73fe commit b6479f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion hexrdgui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions hexrdgui/image_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit b6479f0

Please sign in to comment.