oidstore.py 文件源码

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

项目:mist.api 作者: mistio 项目源码 文件源码
def getAssociation(self, server_url, handle=None):
        """
        Gets a server url and the handle and finds a matching association that
        has not expired. Expired associations are deleted. The association
        returned is the one with the most recent issuing timestamp.
        """

        query = {'server_url': server_url}
        if handle:
            query.update({'handle': handle.encode('hex')})
        try:
            mist_associations = MistAssociation.objects(**query)
        except me.DoesNotExist:
            mist_associations = []

        filtered_mist_assocs = []

        for assoc in mist_associations:
            if assoc.is_expired():
                assoc.delete()
            else:
                filtered_mist_assocs.append(assoc)

        filtered_mist_assocs = sorted(filtered_mist_assocs,
                                      key=lambda assoc: assoc.issued,
                                      reverse=True)

        if len(filtered_mist_assocs) > 0:
            mist_assoc = filtered_mist_assocs[0]
            association = Association(handle=mist_assoc.handle.decode('hex'),
                                      secret=mist_assoc.secret.decode('hex'),
                                      issued=mist_assoc.issued,
                                      lifetime=mist_assoc.lifetime,
                                      assoc_type=mist_assoc.assoc_type)
            return association

        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号