From 0c9da726f51956b35d71b4d08583f0b5745d4af7 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 27 Nov 2014 21:16:35 +0000 Subject: [PATCH] Switch `open()` for `salt.utils.fopen()` --- salt/states/file.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/salt/states/file.py b/salt/states/file.py index 61e7ad269f..3e579f7670 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -3872,9 +3872,11 @@ def serialize(name, if merge_if_exists: if os.path.isfile(name): if formatter == 'yaml': - existing_data = yaml.safe_load(open(name, 'r')) + with salt.utils.fopen(name, 'r') as fhr: + existing_data = yaml.safe_load(fhr.read()) elif formatter == 'json': - existing_data = json.load(open(name, 'r')) + with salt.utils.fopen(name, 'r') as fhr: + existing_data = json.load(fhr.read()) else: return {'changes': {}, 'comment': ('{0} format is not supported for merging'