def parse_bytes(header):
        """
        Parse a Range header into (bytes, list_of_ranges).  Note that the
        ranges are *inclusive* (like in HTTP, not like in Python
        typically).

        Will return None if the header is invalid
        """
        if not header:
            raise TypeError(
                "The header must not be empty")
        ranges = []
        last_end = 0
        try:
            (units, range) = header.split("=", 1)
            units = units.strip().lower()
            for item in range.split(","):
                if '-' not in item:
                    raise ValueError()
                if item.startswith('-'):
                    # This is a range asking for a trailing chunk
                    if last_end < 0:
                        raise ValueError('too many end ranges')
                    begin = int(item)
                    end = None
                    last_end = -1
                else:
                    (begin, end) = item.split("-", 1)
                    begin = int(begin)
                    if begin < last_end or last_end < 0:
                        print begin, last_end
                        raise ValueError('begin<last_end, or last_end<0')
                    if not end.strip():
                        end = None
                    else:
                        end = int(end)
                    if end is not None and begin > end:
                        raise ValueError('begin>end')
                    last_end = end
                ranges.append((begin, end))
        except __HOLE__, e:
            # In this case where the Range header is malformed,
            # section 14.16 says to treat the request as if the
            # Range header was not present.  How do I log this?
            print e
            return None
        return (units, ranges)
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/webob_0_9/webob/byterange.py/Range.parse_bytes