def dict_get_by_path(d, keypath, default=KeyError, what="?"):
    """
    Get specific value from dict d by dotted key path.
    Keypath "first.second" would look for opts['first']['second'].
    If not present, raises KeyError with helpful error message
    treating str('what') as the human-readable name of the dict or 
    object for which the request is made,
    or returns default if one is specified via 'default' argument.
    """
    optidx = d
    for key in keypath.split('.'):
        try:
            optidx = optidx[key]
        except (KeyError, TypeError) as e:
            if default is KeyError:
                raise KeyError((
                    u"'{key}' within path '{keypath}' not found in '{what}'"
                    ).format(key=key, keypath=keypath, what=what))
            else:
                return default
    return optidx