def get_chunks_in_range(chunks, first_line, num_lines):
 for (i, chunk) in enumerate(chunks):
  lines = chunk[u'lines']
  if (lines[(-1)][0] >= first_line >= lines[0][0]):
   start_index = (first_line - lines[0][0])
   if ((first_line + num_lines) <= lines[(-1)][0]):
    last_index = (start_index + num_lines)
   else:
    last_index = len(lines)
   new_chunk = {u'index': i, u'lines': chunk[u'lines'][start_index:last_index], u'numlines': (last_index - start_index), u'change': chunk[u'change'], u'meta': chunk.get(u'meta', {})}
   (yield new_chunk)
   first_line += new_chunk[u'numlines']
   num_lines -= new_chunk[u'numlines']
   assert (num_lines >= 0)
   if (num_lines == 0):
    break

def get_chunks_in_range ( chunks , first_line , num_lines ) : for ( i , chunk ) in enumerate ( chunks ) : lines = chunk [ u'lines' ] if ( lines [ ( - 1 ) ] [ 0 ] >= first_line >= lines [ 0 ] [ 0 ] ) : start_index = ( first_line - lines [ 0 ] [ 0 ] ) if ( ( first_line + num_lines ) <= lines [ ( - 1 ) ] [ 0 ] ) : last_index = ( start_index + num_lines ) else : last_index = len ( lines ) new_chunk = { u'index' : i , u'lines' : chunk [ u'lines' ] [ start_index : last_index ] , u'numlines' : ( last_index - start_index ) , u'change' : chunk [ u'change' ] , u'meta' : chunk . get ( u'meta' , { } ) } ( yield new_chunk ) first_line += new_chunk [ u'numlines' ] num_lines -= new_chunk [ u'numlines' ] assert ( num_lines >= 0 ) if ( num_lines == 0 ) : break
generate the chunks within a range of lines of a larger list of chunks .