def write_policy_file(self, policy, format='yaml'):
""" Write a policy file to disk in the specified format.
Input a dictionary and a format. Valid formats are `yaml` and `json`
Returns the file path.
"""
fh = tempfile.NamedTemporaryFile(mode='w+b', suffix='.' + format)
if format == 'json':
fh.write(json.dumps(policy).encode('utf8'))
else:
fh.write(yaml.dump(policy, encoding='utf8', Dumper=yaml.SafeDumper))
fh.flush()
self.addCleanup(fh.close)
return fh.name
评论列表
文章目录