@staticmethod
  def _calculate_writes_for_composite_index(entity, index):
    composite_index_value_count = 1
    for prop_name, _ in index.Properties():
      if not prop_name in entity.keys() or (
          prop_name in entity.unindexed_properties()):
        return 0
      prop_vals = entity[prop_name]
      if isinstance(prop_vals, (list)):
        composite_index_value_count *= len(prop_vals)

    # If this is an ancestor index we're going to duplicate all these index
    # writes for every key in the hierarchy.  So if the entity key has no
    # parent we write the index values once, if the entity key has a depth of
    # 2 then we write the index values twice, and so on.
    ancestor_count = 1  # A key is its own ancestor.
    if index.HasAncestor():
      key = entity.key().parent()
      while key is not None:
        ancestor_count += 1
        key = key.parent()
    return composite_index_value_count * ancestor_count
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/tools/devappserver2/admin/datastore_viewer.py/DatastoreRequestHandler._calculate_writes_for_composite_index/original