def _handle_range_header(self, request, headers, response_content):
    response_headers = {}
    length = len(response_content)
    last = (length - 1)
    (_, rspec) = request.headers.get('range').split('=')
    if (',' in rspec):
        raise NotImplementedError('Multiple range specifiers not supported')

    def toint(i):
        return (int(i) if i else None)
    (begin, end) = map(toint, rspec.split('-'))
    if (begin is not None):
        end = (last if (end is None) else min(end, last))
    elif (end is not None):
        begin = (length - min(end, length))
        end = last
    else:
        return (400, response_headers, '')
    if ((begin < 0) or (end > last) or (begin > min(end, last))):
        raise InvalidRange(actual_size=str(length), range_requested=request.headers.get('range'))
    response_headers['content-range'] = 'bytes {0}-{1}/{2}'.format(begin, end, length)
    content = response_content[begin:(end + 1)]
    response_headers['content-length'] = len(content)
    return (206, response_headers, content)
def _handle_range_header(self, request, headers, response_content):
    response_headers = {}
    length = len(response_content)
    last = (length - 1)
    (_, rspec) = request.headers.get('range').split('=')
    if (',' in rspec):
        raise NotImplementedError('Multiple range specifiers not supported')

    def toint(i):
        return (int(i) if i else None)
    (begin, end) = map(toint, rspec.split('-'))
    if (begin is not None):
        end = (last if (end is None) else min(end, last))
    elif (end is not None):
        begin = (length - min(end, length))
        end = last
    else:
        return (400, response_headers, )
    if ((begin < 0) or (end > last) or (begin > min(end, last))):
        raise InvalidRange(actual_size=str(length), range_requested=request.headers.get('range'))
    response_headers['content-range'] = 'bytes {0}-{1}/{2}'.format(begin, end, length)
    content = response_content[begin:(end + 1)]
    response_headers['content-length'] = len(content)
    return (206, response_headers, content)