'Given a yaml file and full key, find the span of the value for the key.
If the key does not exist, then return how we should modify the file
around the insertion point so that the context is there.
Args:
source: [string] The YAML source text.
root_node: [yaml.nodes.MappingNode]  The composed yaml tree
full_key: [string] Dot-delimited path whose value we\'re looking for
raise_if_not_found: [boolean] Whether to raise a KeyError or return
additional context if key isnt found.
Returns:
context, span
where:
context:[string, string)]: Text to append before and after the cut.
span: [(int, int)]: The start/end range of source with existing value
to cut.'

def find_yaml_context(self, source, root_node, full_key, raise_if_not_found):

    parts = full_key.split('.')
    if (not isinstance(root_node, yaml.nodes.MappingNode)):
        if ((not root_node) and (not raise_if_not_found)):
            return ((self._make_missing_key_text('', parts), '\n'), (0, 0))
        else:
            raise ValueError((root_node.__class__.__name__ + '    is    not    a    yaml    node.'))
    closest_node = None
    for (key_index, key) in enumerate(parts):
        found = False
        for node in root_node.value:
            if (node[0].value == key):
                closest_node = node
                found = True
                break
        if (not found):
            break
        root_node = closest_node[1]
    if (closest_node is None):
        if raise_if_not_found:
            raise KeyError(full_key)
        return ((self._make_missing_key_text('', parts), '\n'), (0, 0))
    span = (closest_node[1].start_mark.index, closest_node[1].end_mark.index)
    span_is_empty = (span[0] == span[1])
    if found:
        return ((('    ' if span_is_empty else ''), ''), span)
    if raise_if_not_found:
        raise KeyError('.'.join(parts[0:(key_index + 1)]))
    line_start = (closest_node[0].start_mark.index - 1)
    while ((line_start >= 0) and (source[line_start] == '    ')):
        line_start -= 1
    indent = ('    ' * ((closest_node[0].start_mark.index - line_start) + 1))
    key_text = self._make_missing_key_text(indent, parts[key_index:])
    if span_is_empty:
        key_text = ('        ' + prefix)
    return ((key_text, ('\n' + indent)), (span[0], span[0]))
