我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用google.appengine.ext.db.class_for_kind()。
def encode_xdb_key(key, encoder=None): """ Convert the `db.Key` to it's entity and encode it. """ gae_objects = getGAEObjects(encoder.context.extra) klass = db.class_for_kind(key.kind()) try: referenced_object = gae_objects.get(klass, key) except KeyError: referenced_object = db.get(key) gae_objects.set(klass, key, referenced_object) if not referenced_object: encoder.writeElement(None) else: encoder.writeObject(referenced_object)
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