Пример #1
0
 def pb_to_entity(self, pb):
   kind = None
   if pb.has_key():
     # TODO: Fix the inefficiency here: we extract the key just so we
     # can get the kind just so we can find the intended model class,
     # but the key is extracted again and stored in the entity by FromPb().
     key = Key(reference=pb.key())
     kind = key.kind()
   modelclass = Model._kind_map.get(kind, self.default_model)
   if modelclass is None:
     raise KindError("No implementation found for kind '%s'" % kind)
   ent = modelclass()
   ent.FromPb(pb)
   return ent
Пример #2
0
  def default_memcache_timeout_policy(key):
    """Default memcache timeout policy.

    This defers to _memcache_timeout on the Model class.

    Args:
      key: Key instance.

    Returns:
      Memcache timeout to use (integer), or None.
    """
    timeout = None
    if key is not None:
      modelclass = model.Model._kind_map.get(key.kind())
      if modelclass is not None:
        policy = getattr(modelclass, '_memcache_timeout', None)
        if policy is not None:
          if isinstance(policy, (int, long)):
            timeout = policy
          else:
            timeout = policy(key)
    return timeout
Пример #3
0
  def default_datastore_policy(key):
    """Default datastore policy.

    This defers to _use_datastore on the Model class.

    Args:
      key: Key instance.

    Returns:
      A bool or None.
    """
    flag = None
    if key is not None:
      modelclass = model.Model._kind_map.get(key.kind())
      if modelclass is not None:
        policy = getattr(modelclass, '_use_datastore', None)
        if policy is not None:
          if isinstance(policy, bool):
            flag = policy
          else:
            flag = policy(key)
    return flag