def get_block_edges(source_file):
 block_edges = []
 with open(source_file) as f:
  token_iter = tokenize.generate_tokens(f.readline)
  for token_tuple in token_iter:
   (t_id, t_str, (srow, scol), (erow, ecol), src_line) = token_tuple
   if ((token.tok_name[t_id] == 'STRING') and (scol == 0)):
    block_edges.extend((srow, (erow + 1)))
 idx_first_text_block = 0
 if (not (block_edges[0] == 1)):
  block_edges.insert(0, 1)
  idx_first_text_block = 1
 if (not (block_edges[(-1)] == erow)):
  block_edges.append(erow)
 return (block_edges, idx_first_text_block)

def get_block_edges ( source_file ) : block_edges = [ ] with open ( source_file ) as f : token_iter = tokenize . generate_tokens ( f . readline ) for token_tuple in token_iter : ( t_id , t_str , ( srow , scol ) , ( erow , ecol ) , src_line ) = token_tuple if ( ( token . tok_name [ t_id ] == 'STRING' ) and ( scol == 0 ) ) : block_edges . extend ( ( srow , ( erow + 1 ) ) ) idx_first_text_block = 0 if ( not ( block_edges [ 0 ] == 1 ) ) : block_edges . insert ( 0 , 1 ) idx_first_text_block = 1 if ( not ( block_edges [ ( - 1 ) ] == erow ) ) : block_edges . append ( erow ) return ( block_edges , idx_first_text_block )
return starting line numbers of code and text blocks returns block_edges : list of int line number for the start of each block .