def resolve(obj, attrspec):
    """
    Resolve elements from an object.
    Works with objects and dicts.
    From: http://stackoverflow.com/a/9101577/1309774
    """
    for attr in attrspec.split("."):
        try:
            obj = obj[attr]
        except (TypeError, KeyError):
            obj = getattr(obj, attr)
    return obj