nodes: 0, module; 1, function_definition; 2, function_name:compress_and_sort_index; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, try_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, comment:# Include UTF-8 BOM in header.; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, for_statement; 18, expression_statement; 19, expression_statement; 20, with_statement; 21, expression_statement; 22, return_statement; 23, comment:"""Sort index, add header, and compress.
  
          :rtype: bool
          :returns: True
  
          """; 24, assignment; 25, block; 26, except_clause; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, call; 34, identifier:line; 35, identifier:sorted_index; 36, block; 37, assignment; 38, call; 39, with_clause; 40, block; 41, call; 42, True; 43, identifier:idx_fname; 44, call; 45, expression_statement; 46, identifier:IOError; 47, block; 48, identifier:index; 49, list_comprehension; 50, identifier:sorted_index; 51, call; 52, identifier:gzip_idx_fname; 53, binary_operator:idx_fname + '.gz'; 54, identifier:header; 55, list; 56, identifier:s; 57, call; 58, identifier:writer; 59, call; 60, attribute; 61, argument_list; 62, expression_statement; 63, identifier:compressed_index; 64, call; 65, attribute; 66, argument_list; 67, with_item; 68, expression_statement; 69, attribute; 70, argument_list; 71, attribute; 72, argument_list; 73, assignment; 74, return_statement; 75, identifier:x; 76, for_in_clause; 77, if_clause; 78, identifier:sorted; 79, argument_list; 80, identifier:idx_fname; 81, string; 82, string; 83, string; 84, string; 85, string; 86, string; 87, string; 88, string; 89, string; 90, attribute; 91, argument_list; 92, attribute; 93, argument_list; 94, identifier:writer; 95, identifier:writerow; 96, identifier:header; 97, call; 98, identifier:inline_compress_chunk; 99, argument_list; 100, identifier:s; 101, identifier:close; 102, as_pattern; 103, call; 104, identifier:os; 105, identifier:remove; 106, identifier:idx_fname; 107, string; 108, identifier:format; 109, dictionary_splat; 110, identifier:reader; 111, call; 112, False; 113, identifier:x; 114, identifier:reader; 115, identifier:x; 116, identifier:index; 117, keyword_argument; 118, string_content:.gz; 119, string_content; 120, string_content:msg_id; 121, string_content:from; 122, string_content:newsgroups; 123, string_content:subject; 124, string_content:references; 125, string_content:start; 126, string_content:length; 127, identifier:cStringIO; 128, identifier:StringIO; 129, identifier:csv; 130, identifier:writer; 131, identifier:s; 132, keyword_argument; 133, attribute; 134, argument_list; 135, call; 136, call; 137, as_pattern_target; 138, attribute; 139, argument_list; 140, string_content:{name}.{date}.mbox.csv; 141, attribute; 142, attribute; 143, argument_list; 144, identifier:key; 145, call; 146, escape_sequence:\xef; 147, escape_sequence:\xbb; 148, escape_sequence:\xbf; 149, identifier:dialect; 150, string; 151, identifier:writer; 152, identifier:writerow; 153, identifier:line; 154, attribute; 155, argument_list; 156, identifier:open; 157, argument_list; 158, identifier:fp; 159, identifier:fp; 160, identifier:write; 161, identifier:compressed_index; 162, identifier:self; 163, identifier:__dict__; 164, identifier:csv; 165, identifier:reader; 166, call; 167, keyword_argument; 168, identifier:itemgetter; 169, argument_list; 170, string_content:excel-tab; 171, identifier:s; 172, identifier:getvalue; 173, identifier:gzip_idx_fname; 174, string; 175, identifier:open; 176, argument_list; 177, identifier:dialect; 178, string; 179, integer:0; 180, string_content:ab; 181, identifier:idx_fname; 182, string_content:excel-tab
code: def compress_and_sort_index(self):
          """Sort index, add header, and compress.
  
          :rtype: bool
          :returns: True
  
          """
          idx_fname = '{name}.{date}.mbox.csv'.format(**self.__dict__)
          try:
              reader = csv.reader(open(idx_fname), dialect='excel-tab')
          except IOError:
              return False
          index = [x for x in reader if x]
          sorted_index = sorted(index, key=itemgetter(0))
          gzip_idx_fname = idx_fname + '.gz'
  
          # Include UTF-8 BOM in header.
          header = [
              '\xef\xbb\xbf#date', 'msg_id', 'from', 'newsgroups', 'subject', 'references',
              'start', 'length',
          ]
  
          s = cStringIO.StringIO()
          writer = csv.writer(s, dialect='excel-tab')
          writer.writerow(header)
          for line in sorted_index:
              writer.writerow(line)
          compressed_index = inline_compress_chunk(s.getvalue())
          s.close()
  
          with open(gzip_idx_fname, 'ab') as fp:
              fp.write(compressed_index)
          os.remove(idx_fname)
          return True