def __init__(self, stream, renderers, context={}, tmplpath=None, **kwargs): SaltYamlSafeLoader.__init__(self, stream, dictclass=OrderedDict) self.context = context self.tmplpath = tmplpath self.renderers = renderers self.add_constructor(u'!read', type(self)._yamlet_read) self.add_constructor(u'!include', type(self)._yamlet_include) self.add_constructor(u'!read_b64encoded', type(self)._yamlet_read_b64)
def __init__(self, stream, renderers, context=None, tmplpath=None, **_kwargs): SaltYamlSafeLoader.__init__(self, stream, dictclass=OrderedDict) if context is None: self.context = {} else: self.context = context self.tmplpath = tmplpath self.renderers = renderers self.add_constructor("!read", type(self)._yamlet_read) self.add_constructor("!include", type(self)._yamlet_include)
def _render_yaml(data): ''' Takes a YAML string, puts it into a mock file, passes that to the YAML SaltYamlSafeLoader and then returns the rendered/parsed YAML data ''' with patch('salt.utils.fopen', mock_open(read_data=data)) as mocked_file: with salt.utils.fopen(mocked_file) as mocked_stream: return SaltYamlSafeLoader(mocked_stream).get_data()
def render_yaml(data): ''' Takes a YAML string, puts it into a mock file, passes that to the YAML SaltYamlSafeLoader and then returns the rendered/parsed YAML data ''' if six.PY2: # On Python 2, data read from a filehandle will not already be # unicode, so we need to encode it first to properly simulate # reading from a file. This is because unicode_literals is imported # and all of the data to be used in mock_open will be a unicode # type. Encoding will make it a str. data = salt.utils.data.encode(data) with patch('salt.utils.files.fopen', mock_open(read_data=data)) as mocked_file: with salt.utils.files.fopen(mocked_file) as mocked_stream: return SaltYamlSafeLoader(mocked_stream).get_data()
def yaml_loader(*args): return SaltYamlSafeLoader(*args, dictclass=OrderedDict)