'Transform the given yaml source so its value of key matches the binding.
Has no effect if key is not among the bindings.
But raises a KeyError if it is in the bindings but not in the source.
Args:
source [string]: A YAML document
key [string]: A key into the bindings.
add_new_nodes [boolean]: If true, add node for key if not already present.
Otherwise raise a KeyError.
Returns:
Transformed source with value of key replaced to match the bindings.'

def transform_yaml_source(self, source, key, add_new_nodes=True):

    try:
        value = self[key]
    except KeyError:
        return source
    if (isinstance(value, basestring) and re.search('{[^}]*{', value)):
        value = '"{0}"'.format(value)
    if isinstance(value, bool):
        value = str(value).lower()
    yaml_root = yaml.compose(source)
    (context, span) = self.find_yaml_context(source, yaml_root, key, (not add_new_nodes))
    text_before = context[0]
    text_after = context[1]
    start_cut = span[0]
    end_cut = span[1]
    return ''.join([source[0:start_cut], text_before, '{value}'.format(value=value), text_after, source[end_cut:]])
