'Parse the value of a Range header into (start, stop) pairs.
In a given pair, either of start or stop can be None, signifying that
no value was provided, but not both.
@return: A list C{[(start, stop)]} of pairs of length at least one.
@raise ValueError: if the header is syntactically invalid or if the
Bytes-Unit is anything other than \'bytes\'.'

def _parseRangeHeader(self, range):

    try:
        (kind, value) = range.split('=', 1)
    except ValueError:
        raise ValueError("Missing    '='    separator")
    kind = kind.strip()
    if (kind != 'bytes'):
        raise ValueError(('Unsupported    Bytes-Unit:    %r' % (kind,)))
    unparsedRanges = list(filter(None, map(bytes.strip, value.split(','))))
    parsedRanges = []
    for byteRange in unparsedRanges:
        try:
            (start, end) = byteRange.split('-', 1)
        except ValueError:
            raise ValueError(('Invalid    Byte-Range:    %r' % (byteRange,)))
        if start:
            try:
                start = int(start)
            except ValueError:
                raise ValueError(('Invalid    Byte-Range:    %r' % (byteRange,)))
        else:
            start = None
        if end:
            try:
                end = int(end)
            except ValueError:
                raise ValueError(('Invalid    Byte-Range:    %r' % (byteRange,)))
        else:
            end = None
        if (start is not None):
            if ((end is not None) and (start > end)):
                raise ValueError(('Invalid    Byte-Range:    %r' % (byteRange,)))
        elif (end is None):
            raise ValueError(('Invalid    Byte-Range:    %r' % (byteRange,)))
        parsedRanges.append((start, end))
    return parsedRanges
