original_docstring: Writes the given given entities.
  
      Updates an entity's key and entity_group in place if needed
  
      Args:
        raw_entities: A list of unverified entity_pb.EntityProto objects.
        cost: Out param. The cost of putting the provided entities.
        transaction: The datastore_pb.Transaction to use or None.
        trusted: If the calling app is trusted.
        calling_app: The app requesting the results or None to pull the app from
          the environment.
      Returns:
        A list of entity_pb.Reference objects that indicates where each entity
        was stored.
      
docstring: Writes the given given entities.
  Updates an entity's key and entity_group in place if needed
docstring_tokens: Writes the given given entities . Updates an entity ' s key and entity_group in place if needed
code: def Put(self, raw_entities, cost, transaction=None,
            trusted=False, calling_app=None):
      """Writes the given given entities.
  
      Updates an entity's key and entity_group in place if needed
  
      Args:
        raw_entities: A list of unverified entity_pb.EntityProto objects.
        cost: Out param. The cost of putting the provided entities.
        transaction: The datastore_pb.Transaction to use or None.
        trusted: If the calling app is trusted.
        calling_app: The app requesting the results or None to pull the app from
          the environment.
      Returns:
        A list of entity_pb.Reference objects that indicates where each entity
        was stored.
      """
      if not raw_entities:
        return []
  
      calling_app = datastore_types.ResolveAppId(calling_app)
  
  
      result = [None] * len(raw_entities)
      grouped_entities = collections.defaultdict(list)
      for i, raw_entity in enumerate(raw_entities):
        CheckEntity(trusted, calling_app, raw_entity)
  
  
  
        entity = entity_pb.EntityProto()
        entity.CopyFrom(raw_entity)
  
  
        for prop in itertools.chain(entity.property_list(),
                                    entity.raw_property_list()):
          FillUser(prop)
  
        last_element = entity.key().path().element_list()[-1]
        if not (last_element.id() or last_element.has_name()):
          insert = True
  
  
          if self._auto_id_policy == SEQUENTIAL:
            last_element.set_id(self._AllocateIds(entity.key())[0])
          else:
            full_key = self._AllocateScatteredIds([entity.key()])[0]
            last_element.set_id(full_key.path().element_list()[-1].id())
        else:
          insert = False
  
        entity_group = _GetEntityGroup(entity.key())
        entity.mutable_entity_group().CopyFrom(entity_group.path())
        entity_group_key = datastore_types.ReferenceToKeyValue(entity_group)
        grouped_entities[entity_group_key].append((entity, insert))
  
  
  
        key = entity_pb.Reference()
        key.CopyFrom(entity.key())
        result[i] = key
  
      if transaction:
  
        txn = self.GetTxn(transaction, trusted, calling_app)
        for group in grouped_entities.values():
          for entity, insert in group:
  
            indexes = _FilterIndexesByKind(entity.key(), self.GetIndexes(
                entity.key().app(), trusted, calling_app))
            txn.Put(entity, insert, indexes)
      else:
  
        for entities in grouped_entities.itervalues():
          txn_cost = self._RunInTxn(
              entities, entities[0][0].key().app(),
  
              lambda txn, v: txn.Put(v[0], v[1], _FilterIndexesByKind(
                  v[0].key(),
                  self.GetIndexes(v[0].key().app(), trusted, calling_app))))
          _UpdateCost(cost, txn_cost.entity_writes(), txn_cost.index_writes())
      return result
code_tokens: def Put ( self , raw_entities , cost , transaction = None , trusted = False , calling_app = None ) : if not raw_entities : return [ ] calling_app = datastore_types . ResolveAppId ( calling_app ) result = [ None ] * len ( raw_entities ) grouped_entities = collections . defaultdict ( list ) for i , raw_entity in enumerate ( raw_entities ) : CheckEntity ( trusted , calling_app , raw_entity ) entity = entity_pb . EntityProto ( ) entity . CopyFrom ( raw_entity ) for prop in itertools . chain ( entity . property_list ( ) , entity . raw_property_list ( ) ) : FillUser ( prop ) last_element = entity . key ( ) . path ( ) . element_list ( ) [ - 1 ] if not ( last_element . id ( ) or last_element . has_name ( ) ) : insert = True if self . _auto_id_policy == SEQUENTIAL : last_element . set_id ( self . _AllocateIds ( entity . key ( ) ) [ 0 ] ) else : full_key = self . _AllocateScatteredIds ( [ entity . key ( ) ] ) [ 0 ] last_element . set_id ( full_key . path ( ) . element_list ( ) [ - 1 ] . id ( ) ) else : insert = False entity_group = _GetEntityGroup ( entity . key ( ) ) entity . mutable_entity_group ( ) . CopyFrom ( entity_group . path ( ) ) entity_group_key = datastore_types . ReferenceToKeyValue ( entity_group ) grouped_entities [ entity_group_key ] . append ( ( entity , insert ) ) key = entity_pb . Reference ( ) key . CopyFrom ( entity . key ( ) ) result [ i ] = key if transaction : txn = self . GetTxn ( transaction , trusted , calling_app ) for group in grouped_entities . values ( ) : for entity , insert in group : indexes = _FilterIndexesByKind ( entity . key ( ) , self . GetIndexes ( entity . key ( ) . app ( ) , trusted , calling_app ) ) txn . Put ( entity , insert , indexes ) else : for entities in grouped_entities . itervalues ( ) : txn_cost = self . _RunInTxn ( entities , entities [ 0 ] [ 0 ] . key ( ) . app ( ) , lambda txn , v : txn . Put ( v [ 0 ] , v [ 1 ] , _FilterIndexesByKind ( v [ 0 ] . key ( ) , self . GetIndexes ( v [ 0 ] . key ( ) . app ( ) , trusted , calling_app ) ) ) ) _UpdateCost ( cost , txn_cost . entity_writes ( ) , txn_cost . index_writes ( ) ) return result
short_docstring: Writes the given given entities.
short_docstring_tokens: Writes the given given entities .
comment: """Writes the given given entities.
  
      Updates an entity's key and entity_group in place if needed
  
      Args:
        raw_entities: A list of unverified entity_pb.EntityProto objects.
        cost: Out param. The cost of putting the provided entities.
        transaction: The datastore_pb.Transaction to use or None.
        trusted: If the calling app is trusted.
        calling_app: The app requesting the results or None to pull the app from
          the environment.
      Returns:
        A list of entity_pb.Reference objects that indicates where each entity
        was stored.
      """