core.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:memory-game 作者: thurstonemerson 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号