'Looks up specified key and returns its final value.
Args:
key: [string] Specification of the key to retrieve.
saw: [list of string] The path of keys we\'re chasing down for the value.
original: [string] The original starting point of the |saw| path.
Raises:
KeyError if the |key| is not in the dictionary.
ValueError if a cycle is encountered.'

def __resolve_value(self, key, saw, original):

    value = super(ExpressionDict, self).get(key, None)
    if ((value is None) and (not (key in self))):
        raise KeyError(key)
    if (not isinstance(value, basestring)):
        return value
    if (key in saw):
        raise ValueError(('Cycle    looking    up    variable    ' + original))
    saw = (saw + [key])
    expression_re = re.compile('\\${([\\._a-zA-Z0-9]+)(:.*?)?}')
    exact_match = expression_re.match(value)
    if (exact_match and (exact_match.group(0) == value)):
        try:
            got = self.__resolve_value(exact_match.group(1), saw, original)
            return got
        except KeyError:
            if exact_match.group(2):
                return self.__default_value_interpreter(exact_match.group(2)[1:])
            else:
                return value
    result = []
    offset = 0
    text = value
    for match in expression_re.finditer(text):
        result.append(text[offset:match.start()])
        try:
            got = self.__resolve_value(match.group(1), saw, original)
            result.append(str(got))
        except KeyError:
            if match.group(2):
                result.append(str(match.group(2)[1:]))
            else:
                result.append(match.group(0))
        offset = match.end()
    result.append(text[offset:])
    return ''.join(result)
