def document_iters_to_multipart_byteranges(ranges_iter, boundary):
 divider = (('--' + boundary) + '\r\n')
 terminator = (('--' + boundary) + '--')
 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']
  part_header = ''.join((divider, 'Content-Type: ', str(content_type), '\r\n', 'Content-Range: ', ('bytes %d-%d/%s\r\n' % (start_byte, end_byte, entity_length)), '\r\n'))
  (yield part_header)
  for chunk in part_iter:
   (yield chunk)
  (yield '\r\n')
 (yield terminator)

def document_iters_to_multipart_byteranges ( ranges_iter , boundary ) : divider = ( ( '--' + boundary ) + '\r\n' ) terminator = ( ( '--' + boundary ) + '--' ) 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' ] part_header = '' . join ( ( divider , 'Content-Type: ' , str ( content_type ) , '\r\n' , 'Content-Range: ' , ( 'bytes %d-%d/%s\r\n' % ( start_byte , end_byte , entity_length ) ) , '\r\n' ) ) ( yield part_header ) for chunk in part_iter : ( yield chunk ) ( yield '\r\n' ) ( yield terminator )
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 .