def _expand_ranges(ranges_text, delimiter=',', indicator='-'):
    """ Expands a range text to a list of integers.

    For example:

    .. code-block:: python

        range_text = '1,2-4,7'
        print(_expand_ranges(range_text)) # [1, 2, 3, 4, 7]

    :param str ranges_text: The text of ranges to expand
    :returns: A list of integers
    :rtype: list[int]
    """

    results = set()
    for group in filter(None, ranges_text.split(delimiter)):
        group = group.strip()
        if indicator not in group:
            if not group.isdigit():
                raise ValueError((
                    "group '{group}' could not be interpreted as a valid digit"
                ).format(**locals()))
            results.add(int(group))
        else:
            (start, finish,) = list(filter(None, group.split(indicator)))
            if not start.isdigit() or not finish.isdigit():
                raise ValueError((
                    "group '{group}' could not be interpreted as a valid range"
                ).format(**locals()))
            for entry in range(int(start), (int(finish) + 1), 1):
                results.add(entry)
    return sorted(list(results))