def expandRanges(ranges, size):
    """Expand Range sets, given those sets and the length of the resource.

    Expansion means relative start values and open ends
    """
    expanded = []
    add = expanded.append
    for start, end in ranges:
        if start < 0:
            start = size + start
        end = end or size
        if end > size:
            end = size
        if start < size:
            add((start, end))
    return expanded
