我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用google.appengine.ext.db.KindError()。
def from_entity(cls, entity): """Load from entity to class based on discriminator. Rather than instantiating a new Model instance based on the kind mapping, this creates an instance of the correct model class based on the entities class-key. Args: entity: Entity loaded directly from datastore. Raises: KindError when there is no class mapping based on discriminator. """ if (_CLASS_KEY_PROPERTY in entity and tuple(entity[_CLASS_KEY_PROPERTY]) != cls.class_key()): key = tuple(entity[_CLASS_KEY_PROPERTY]) try: poly_class = _class_map[key] except KeyError: raise db.KindError('No implementation for class \'%s\'' % (key,)) return poly_class.from_entity(entity) return super(PolyModel, cls).from_entity(entity)
def GetImplementationClass(kind_or_class_key): """Returns the implementation class for a given kind or class key. Args: kind_or_class_key: A kind string or a tuple of kind strings. Return: A db.Model subclass for the given kind or class key. """ if isinstance(kind_or_class_key, tuple): try: implementation_class = polymodel._class_map[kind_or_class_key] except KeyError: raise db.KindError('No implementation for class \'%s\'' % kind_or_class_key) else: implementation_class = db.class_for_kind(kind_or_class_key) return implementation_class
def get_object(model, *filters_or_key, **kwargs): if kwargs.get('key_name'): item = model.get_by_key_name(kwargs.get('key_name'), parent=kwargs.get('parent')) elif kwargs.get('id'): item = model.get_by_id(kwargs.get('id'), parent=kwargs.get('parent')) elif len(filters_or_key) > 1: item = get_filtered(model.all(), *filters_or_key).get() else: error = None if isinstance(filters_or_key[0], (tuple, list)): error = [None for index in range(len(filters_or_key[0]))] try: item = model.get(filters_or_key[0]) except (db.BadKeyError, db.KindError): return error return item