def get_by_urlsafe(self, urlsafe):
"""Returns an ndb.Model entity that the urlsafe key points to. Checks
that the type of entity returned is of the correct kind. Raises an
error if the key String is malformed or the entity is of the incorrect
kind.
:param urlsafe: A urlsafe key string
"""
try:
key = ndb.Key(urlsafe=urlsafe)
except TypeError:
raise endpoints.BadRequestException('Invalid Key')
except Exception, e:
if e.__class__.__name__ == 'ProtocolBufferDecodeError':
raise endpoints.BadRequestException('Invalid Key')
else:
raise
model = key.get()
if not model:
return None
self._isinstance(model)
return model
评论列表
文章目录