import itertools
import six


def iterate_allocations(path, alloc):
    """Generate (path, alloc) tuples for the leaves of the allocation tree."""
    if not alloc.sub_allocations:
        return iter([('/'.join(path), alloc)])
    else:
        def _chain(acc, item):
            """Chains allocation iterators."""
            name, suballoc = item
            return itertools.chain(
                acc,
                iterate_allocations(path + [name], suballoc)
            )

        return six.moves.reduce(
            _chain,
            six.iteritems(alloc.sub_allocations),
            []
        )