nodes: 0, module; 1, function_definition; 2, function_name:write_cache; 3, parameters; 4, block; 5, identifier:entries; 6, identifier:stream; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# wrap the stream into a compatible writer; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, comment:# header; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, comment:# body; 19, for_statement; 20, comment:# END for each entry; 21, comment:# write previously cached extensions data; 22, if_statement; 23, comment:# write the sha over the content; 24, expression_statement; 25, identifier:extension_data; 26, None; 27, identifier:ShaStreamCls; 28, identifier:IndexFileSHA1Writer; 29, comment:"""Write the cache represented by entries to a stream
  
      :param entries: **sorted** list of entries
      :param stream: stream to wrap into the AdapterStreamCls - it is used for
          final output.
  
      :param ShaStreamCls: Type to use when writing to the stream. It produces a sha
          while writing to it, before the data is passed on to the wrapped stream
  
      :param extension_data: any kind of data to write as a trailer, it must begin
          a 4 byte identifier, followed by its size ( 4 bytes )"""; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, call; 35, call; 36, identifier:entry; 37, identifier:entries; 38, block; 39, comparison_operator:extension_data is not None; 40, block; 41, call; 42, identifier:stream; 43, call; 44, identifier:tell; 45, attribute; 46, identifier:write; 47, attribute; 48, identifier:version; 49, integer:2; 50, identifier:write; 51, argument_list; 52, identifier:write; 53, argument_list; 54, expression_statement; 55, expression_statement; 56, comment:# ctime; 57, expression_statement; 58, comment:# mtime; 59, expression_statement; 60, expression_statement; 61, expression_statement; 62, comment:# path length; 63, assert_statement; 64, expression_statement; 65, comment:# clear possible previous values; 66, expression_statement; 67, expression_statement; 68, expression_statement; 69, expression_statement; 70, identifier:extension_data; 71, None; 72, expression_statement; 73, attribute; 74, argument_list; 75, identifier:ShaStreamCls; 76, argument_list; 77, identifier:stream; 78, identifier:tell; 79, identifier:stream; 80, identifier:write; 81, string:b"DIRC"; 82, call; 83, assignment; 84, call; 85, call; 86, assignment; 87, assignment; 88, assignment; 89, comparison_operator:plen == len(path); 90, binary_operator:"Path %s too long to fit into index" % entry[3]; 91, assignment; 92, call; 93, call; 94, assignment; 95, call; 96, call; 97, identifier:stream; 98, identifier:write_sha; 99, identifier:stream; 100, identifier:pack; 101, argument_list; 102, identifier:beginoffset; 103, call; 104, identifier:write; 105, argument_list; 106, identifier:write; 107, argument_list; 108, identifier:path; 109, subscript; 110, identifier:path; 111, call; 112, identifier:plen; 113, binary_operator:len(path) & CE_NAMEMASK; 114, identifier:plen; 115, call; 116, string:"Path %s too long to fit into index"; 117, subscript; 118, identifier:flags; 119, binary_operator:plen | (entry[2] & CE_NAMEMASK_INV); 120, identifier:write; 121, argument_list; 122, identifier:write; 123, argument_list; 124, identifier:real_size; 125, parenthesized_expression; 126, identifier:write; 127, argument_list; 128, attribute; 129, argument_list; 130, string:">LL"; 131, identifier:version; 132, call; 133, identifier:tell; 134, argument_list; 135, subscript; 136, subscript; 137, identifier:entry; 138, integer:3; 139, identifier:force_bytes; 140, argument_list; 141, call; 142, identifier:CE_NAMEMASK; 143, identifier:len; 144, argument_list; 145, identifier:entry; 146, integer:3; 147, identifier:plen; 148, parenthesized_expression; 149, call; 150, identifier:path; 151, binary_operator:(tell() - beginoffset + 8) & ~7; 152, binary_operator:b"\0" * ((beginoffset + real_size) - tell()); 153, identifier:stream; 154, identifier:write; 155, identifier:extension_data; 156, identifier:len; 157, argument_list; 158, identifier:entry; 159, integer:4; 160, identifier:entry; 161, integer:5; 162, identifier:path; 163, keyword_argument; 164, identifier:len; 165, argument_list; 166, identifier:path; 167, binary_operator:entry[2] & CE_NAMEMASK_INV; 168, identifier:pack; 169, argument_list; 170, parenthesized_expression; 171, unary_operator; 172, string:b"\0"; 173, parenthesized_expression; 174, identifier:entries; 175, identifier:encoding; 176, identifier:defenc; 177, identifier:path; 178, subscript; 179, identifier:CE_NAMEMASK_INV; 180, string:">LLLLLL20sH"; 181, subscript; 182, subscript; 183, subscript; 184, subscript; 185, subscript; 186, subscript; 187, subscript; 188, identifier:flags; 189, binary_operator:tell() - beginoffset + 8; 190, integer:7; 191, binary_operator:(beginoffset + real_size) - tell(); 192, identifier:entry; 193, integer:2; 194, identifier:entry; 195, integer:6; 196, identifier:entry; 197, integer:7; 198, identifier:entry; 199, integer:0; 200, identifier:entry; 201, integer:8; 202, identifier:entry; 203, integer:9; 204, identifier:entry; 205, integer:10; 206, identifier:entry; 207, integer:1; 208, binary_operator:tell() - beginoffset; 209, integer:8; 210, parenthesized_expression; 211, call; 212, call; 213, identifier:beginoffset; 214, binary_operator:beginoffset + real_size; 215, identifier:tell; 216, argument_list; 217, identifier:tell; 218, argument_list; 219, identifier:beginoffset; 220, identifier:real_size
code: def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1Writer):
      """Write the cache represented by entries to a stream
  
      :param entries: **sorted** list of entries
      :param stream: stream to wrap into the AdapterStreamCls - it is used for
          final output.
  
      :param ShaStreamCls: Type to use when writing to the stream. It produces a sha
          while writing to it, before the data is passed on to the wrapped stream
  
      :param extension_data: any kind of data to write as a trailer, it must begin
          a 4 byte identifier, followed by its size ( 4 bytes )"""
      # wrap the stream into a compatible writer
      stream = ShaStreamCls(stream)
  
      tell = stream.tell
      write = stream.write
  
      # header
      version = 2
      write(b"DIRC")
      write(pack(">LL", version, len(entries)))
  
      # body
      for entry in entries:
          beginoffset = tell()
          write(entry[4])         # ctime
          write(entry[5])         # mtime
          path = entry[3]
          path = force_bytes(path, encoding=defenc)
          plen = len(path) & CE_NAMEMASK      # path length
          assert plen == len(path), "Path %s too long to fit into index" % entry[3]
          flags = plen | (entry[2] & CE_NAMEMASK_INV)     # clear possible previous values
          write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0],
                     entry[8], entry[9], entry[10], entry[1], flags))
          write(path)
          real_size = ((tell() - beginoffset + 8) & ~7)
          write(b"\0" * ((beginoffset + real_size) - tell()))
      # END for each entry
  
      # write previously cached extensions data
      if extension_data is not None:
          stream.write(extension_data)
  
      # write the sha over the content
      stream.write_sha()