import functools


def rgetattr(obj, attr, *args): # pragma: no cover
    """
    A replacement of the default getattr() with a nuance of getting the nested values from objects
    :param obj: Object to lookup
    :param attr: Attribute to search
    :param args: Defaut value
    :return: Value
    """

    def _getattr(obj, attr):
        return getattr(obj, attr, *args)

    return functools.reduce(_getattr, [obj] + attr.split('.'))