当前位置: 首页>>代码示例>>Python>>正文


Python ScAddr.parse_binary方法代码示例

本文整理汇总了Python中sctp.types.ScAddr.parse_binary方法的典型用法代码示例。如果您正苦于以下问题:Python ScAddr.parse_binary方法的具体用法?Python ScAddr.parse_binary怎么用?Python ScAddr.parse_binary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sctp.types.ScAddr的用法示例。


在下文中一共展示了ScAddr.parse_binary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_binary [as 别名]
    def get(self):
        result = None
    
    
        # get arguments
        substr = self.get_argument('substr', None)
        
        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host = tornado.options.options.redis_host, 
                              port = tornado.options.options.redis_port,
                              db = tornado.options.options.redis_db_idtf)
        result = {}
        sys = []
        main = []
        common = []
        max_n = tornado.options.options.idtf_serach_limit
        
        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 200)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])
            if cursor == 0:
                break
            for idtf in reply[1]:
                if len(sys) == max_n and len(main) == max_n and len(common) == max_n:
                    break
                
                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < max_n:
                    sys.append([addr.to_id(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < max_n:
                    main.append([addr.to_id(), utf[10:]])
                elif utf.startswith(u"idtf:common:") and len(common) < max_n:
                    common.append([addr.to_id(), utf[12:]])
                    

        sctp_client = new_sctp_client()
        keys = Keynodes(sctp_client)
        keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
        keynode_nrel_system_identifier = keys[KeynodeSysIdentifiers.nrel_system_identifier]
        keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]
                    
        result[keynode_nrel_system_identifier.to_id()] = sys
        result[keynode_nrel_main_idtf.to_id()] = main
        result[keynode_nrel_idtf.to_id()] = common
        
        sctp_client.shutdown()
        self.set_header("Content-Type", "application/json")
        self.finish(json.dumps(result))
开发者ID:DmitryKus,项目名称:sc-web,代码行数:56,代码来源:api.py

示例2: idtf_find

# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_binary [as 别名]
def idtf_find(request):
    result = None
    if request.is_ajax():
        # get arguments
        substr = request.GET.get('substr', None)
        
        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host = settings.REDIS_HOST, port = settings.REDIS_PORT, db = settings.REDIS_DB)
        result = {}
        sys = []
        main = []
        common = []
        
        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 200)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])
            if cursor == 0:
                break
            for idtf in reply[1]:
                if len(sys) == settings.IDTF_SEARCH_LIMIT and len(main) == settings.IDTF_SEARCH_LIMIT and len(common) == settings.IDTF_SEARCH_LIMIT:
                    break
                
                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < settings.IDTF_SEARCH_LIMIT:
                    sys.append([addr.to_id(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < settings.IDTF_SEARCH_LIMIT:
                    main.append([addr.to_id(), utf[10:]])   
                elif utf.startswith(u"idtf:common:") and len(common) < settings.IDTF_SEARCH_LIMIT:
                    common.append([addr.to_id(), utf[12:]])          
                    

        sctp_client = new_sctp_client()
        keys = Keynodes(sctp_client)    
        keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
        keynode_nrel_system_identifier = keys[KeynodeSysIdentifiers.nrel_system_identifier]
        keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]
                    
        result[keynode_nrel_system_identifier.to_id()] = sys
        result[keynode_nrel_main_idtf.to_id()] = main
        result[keynode_nrel_idtf.to_id()] = common
        
        result = json.dumps(result)

    return HttpResponse(result, 'application/json')
开发者ID:antonSuprun,项目名称:sc-web,代码行数:52,代码来源:views.py

示例3: get

# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_binary [as 别名]
    def get(self):
        result = None
    
    
        # get arguments
        substr = self.get_argument('substr', None)
        
        # connect to redis an try to find identifiers
        r = redis.StrictRedis(host = tornado.options.options.redis_host, 
                              port = tornado.options.options.redis_port,
                              db = tornado.options.options.redis_db_idtf)
        result = {}
        sys = []
        main = []
        common = []
        max_n = tornado.options.options.idtf_serach_limit
        
        def appendSorted(array, data):
            if len(array) > 0:
                idx = 0
                inserted = False
                for idx in xrange(len(array)):
                    if len(array[idx][1]) > len(data[1]):
                        array.insert(idx, data)
                        inserted = True
                        break;
                    idx = idx + 1
                
                if not inserted and len(array) < max_n:
                    array.append(data)
                
                if (len(array) > max_n):
                    array.pop()
            else:
                array.append(data)
        
        # first of all need to find system identifiers
        cursor = 0
        while True:
            reply = r.scan(cursor, u"idtf:*%s*" % substr, 1000)
            if not reply or len(reply) == 0:
                break
            cursor = int(reply[0])
            
            for idtf in reply[1]:
                if len(sys) == max_n and len(main) == max_n and len(common) == max_n:
                    break
                
                rep = r.get(idtf)
                utf = idtf.decode('utf-8')
                addr = ScAddr.parse_binary(rep)
                if utf.startswith(u"idtf:sys:") and len(sys) < max_n:
                    appendSorted(sys, [addr.to_int(), utf[9:]])
                elif utf.startswith(u"idtf:main:") and len(main) < max_n:
                    appendSorted(main, [addr.to_int(), utf[10:]])
                elif utf.startswith(u"idtf:common:") and len(common) < max_n:
                    appendSorted(common, [addr.to_int(), utf[12:]])

            if cursor == 0:
                break
                                
        with SctpClientInstance() as sctp_client:
            keys = Keynodes(sctp_client)
            keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
            keynode_nrel_system_identifier = keys[KeynodeSysIdentifiers.nrel_system_identifier]
            keynode_nrel_idtf = keys[KeynodeSysIdentifiers.nrel_idtf]
                        
            result['sys'] = sys
            result['main'] = main
            result['common'] = common
            
            self.set_header("Content-Type", "application/json")
            self.finish(json.dumps(result))
开发者ID:blrB,项目名称:sc-web,代码行数:75,代码来源:api.py


注:本文中的sctp.types.ScAddr.parse_binary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。