python类NotSavedError()的实例源码

test_xdb.py 文件源码 项目:Tinychat-Bot--Discontinued 作者: Tinychat 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def encodeKey(self, key, encoding):
        """
        Returns an AMF encoded representation of a L{db.Key} instance.

        @param key: The L{db.Key} to be encoded.
        @type key: L{db.Key}
        @param encoding: The AMF version.
        """
        if hasattr(key, 'key'):
            # we have a db.Model instance
            try:
                key = key.key()
            except db.NotSavedError:
                key = None

        if not key:
            # the AMF representation of None
            if encoding == pyamf.AMF3:
                return '\x01'

            return '\x05'

        k = str(key)

        if encoding == pyamf.AMF3:
            return '\x06%s%s' % (
                amf3.encode_int(len(k) << 1 | amf3.REFERENCE_BIT), k)

        return '\x02%s%s' % (struct.pack('>H', len(k)), k)


问题


面经


文章

微信
公众号

扫码关注公众号