def document_iters_to_multipart_byteranges(ranges_iter, boundary):
    """
    Takes an iterator of range iters and yields a multipart/byteranges MIME
    document suitable for sending as the body of a multi-range 206 response.

    See document_iters_to_http_response_body for parameter descriptions.
    """
    if not isinstance(boundary, bytes):
        boundary = boundary.encode('ascii')
    divider = b'--' + boundary + b'\r\n'
    terminator = b'--' + boundary + b'--'
    for range_spec in ranges_iter:
        start_byte = range_spec['start_byte']
        end_byte = range_spec['end_byte']
        entity_length = range_spec.get('entity_length', '*')
        content_type = range_spec['content_type']
        part_iter = range_spec['part_iter']
        if not isinstance(content_type, bytes):
            content_type = str(content_type).encode('utf-8')
        if not isinstance(entity_length, bytes):
            entity_length = str(entity_length).encode('utf-8')
        part_header = b''.join((divider, b'Content-Type: ', content_type,
            b'\r\n', b'Content-Range: ', b'bytes %d-%d/%s\r\n' % (
            start_byte, end_byte, entity_length), b'\r\n'))
        yield part_header
        for chunk in part_iter:
            yield chunk
        yield b'\r\n'
    yield terminator
