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


Python types.ScAddr类代码示例

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


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

示例1: get_arc

    def get_arc(self, arc):
        """Returns sc-addr of arc element begin
        @param arc sc-addr of arc to get beign
        @return If there are no any errors, then returns sc-addr of arc begin; 
        otherwise returns None
        """
        # send request
        params = struct.pack("=HH", arc.seg, arc.offset)
        data = struct.pack("=BBII", SctpCommandType.SCTP_CMD_GET_ARC, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack("=BIBI", data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack("=HH", data)

        addr2 = ScAddr(0, 0)
        data = self.receiveData(4)
        addr2.seg, addr2.offset = struct.unpack("=HH", data)

        return (addr, addr2)
开发者ID:rusetski-k,项目名称:sc-web,代码行数:28,代码来源:client.py

示例2: create_arc

    def create_arc(self, arc_type, begin_addr, end_addr):
        """Create new arc in sc-memory with specified type and begin, end elements
        @param arc_type: Type of sc-arc
        @param begin_addr: sc-addr of begin arc element
        @param end_addr: sc-addr of end arc element
        @return: If sc-arc was created, then returns it sc-addr; otherwise return None
        """
        # send request
        params = struct.pack('=HHHHH', arc_type, begin_addr.seg, begin_addr.offset, end_addr.seg, end_addr.offset)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_ARC, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
开发者ID:antonSuprun,项目名称:sc-web,代码行数:25,代码来源:client.py

示例3: post

    def post(self):
        result = '[]'
        
        with SctpClientInstance() as sctp_client:
            cmd_addr = ScAddr.parse_from_string(self.get_argument(u'cmd', None))
            # parse arguments
            first = True
            arg = None
            arguments = []
            idx = 0
            while first or (arg is not None):
                arg = ScAddr.parse_from_string(self.get_argument(u'%d_' % idx, None))
                if arg is not None:
                    # check if sc-element exist
                    if sctp_client.check_element(arg):
                        arguments.append(arg)
                    else:
                        return logic.serialize_error(404, "Invalid argument: %s" % arg)
    
                first = False
                idx += 1

            keys = Keynodes(sctp_client)
            result = logic.do_command(sctp_client, keys, cmd_addr, arguments, self)
                 
            self.set_header("Content-Type", "application/json")
            self.finish(json.dumps(result))
开发者ID:blrB,项目名称:sc-web,代码行数:27,代码来源:api.py

示例4: find_links_with_content

    def find_links_with_content(self, data):
        """Find sc-links with specified content
        @param data: Content data for search
        @return: Returns list of sc-addrs of founded sc-links. If there are any error, then return None
        """
        # send request
        params = struct.pack('=I%ds' % len(data), len(data), data)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_FIND_LINKS, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize < 4:
            return None

        res = []
        data = self.receiveData(resSize)
        resCount = struct.unpack('=I', data[:4])[0]
        for i in xrange(resCount):
            addr = ScAddr(0, 0)
            data = data[4:]
            addr.seg, addr.offset = struct.unpack('=HH', data)
            res.append(addr)

        return res
开发者ID:antonSuprun,项目名称:sc-web,代码行数:28,代码来源:client.py

示例5: info_tooltip

def info_tooltip(request):
    result = '[]'
    if request.is_ajax():
        sctp_client = new_sctp_client()

        # parse arguments
        first = True
        arg = None
        arguments = []
        idx = 0
        while first or (arg is not None):
            arg_str = u'%d_' % idx
            arg = request.POST.get(arg_str, None)
            if arg is not None:
                arguments.append(arg)
            first = False
            idx += 1
            
        keys = Keynodes(sctp_client)
        sc_session = logic.ScSession(request.user, request.session, sctp_client, keys)

        res = {}
        for addr in arguments:
            tooltip = find_tooltip(ScAddr.parse_from_string(addr), sctp_client, keys, sc_session.get_used_language())
            res[addr] = tooltip

        result = json.dumps(res)

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

示例6: get

    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,代码行数:54,代码来源:api.py

示例7: post

 def post(self):
     lang_addr = ScAddr.parse_from_string(self.get_argument(u'lang_addr', None))
     
     sctp_client = new_sctp_client()
     keys = Keynodes(sctp_client)
 
     sc_session = logic.ScSession(self, sctp_client, keys)
     sc_session.set_current_lang_mode(lang_addr)
     
     sctp_client.shutdown()
     self.set_header("Content-Type", "application/json")
     self.finish()
开发者ID:DmitryKus,项目名称:sc-web,代码行数:12,代码来源:api.py

示例8: create_link

    def create_link(self):
        """Create new sc-link in memory
        @return: If sc-link was created, then returns it sc-addr; otherwise return None
        """
        # send request
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_LINK, 0, 0, 0)
        alldata = data

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
开发者ID:antonSuprun,项目名称:sc-web,代码行数:21,代码来源:client.py

示例9: idtf_find

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,代码行数:50,代码来源:views.py

示例10: find_element_by_system_identifier

    def find_element_by_system_identifier(self, idtf_data):
        """Find sc-element by it system identifier
        @param idtf_data: Identifier data for search
        @return: Returns sc-addrs of founded sc-element.
        If there are any error or sc-element wasn't found, then return None
        """
        # send request
        params = struct.pack('=I%ds' % len(idtf_data), len(idtf_data), idtf_data)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_FIND_ELEMENT_BY_SYSITDF, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK or resSize < 4:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
开发者ID:antonSuprun,项目名称:sc-web,代码行数:24,代码来源:client.py

示例11: set_language

def set_language(request):
    
    if (request.is_ajax()):
        
        lang_addr = ScAddr.parse_from_string(request.POST.get(u'lang_addr', None))
        
        sctp_client = new_sctp_client()
        keys = Keynodes(sctp_client)
        
        sc_session = logic.ScSession(request.user, request.session, sctp_client, keys)
        sc_session.set_current_lang_mode(lang_addr)
        
        result = json.dumps('')
    
    return HttpResponse(result, 'application/json')
开发者ID:bakhmetow,项目名称:repo,代码行数:15,代码来源:views.py

示例12: create_node

    def create_node(self, el_type):
        """Create new sc-node in memory with specified type
        @param el_type: Type of node that would be created
        @return: If sc-node was created, then returns it sc-addr; otherwise return None
        """

        # send request
        params = struct.pack('=H', el_type)
        data = struct.pack('=BBII', SctpCommandType.SCTP_CMD_CREATE_NODE, 0, 0, len(params))
        alldata = data + params

        self.sock.send(alldata)

        # receive response
        data = self.receiveData(10)
        cmdCode, cmdId, resCode, resSize = struct.unpack('=BIBI', data)
        if resCode != SctpResultCode.SCTP_RESULT_OK:
            return None

        addr = ScAddr(0, 0)
        data = self.receiveData(4)
        addr.seg, addr.offset = struct.unpack('=HH', data)

        return addr
开发者ID:antonSuprun,项目名称:sc-web,代码行数:24,代码来源:client.py

示例13: link_content

def link_content(request):
    result = '{}'
    if True:  # request.is_ajax():
        sctp_client = new_sctp_client()

        keys = Keynodes(sctp_client)
        keynode_nrel_format = keys[KeynodeSysIdentifiers.nrel_format]
        keynode_nrel_mimetype = keys[KeynodeSysIdentifiers.nrel_mimetype]

        # parse arguments
        addr = ScAddr.parse_from_string(request.GET.get('addr', None))
        if addr is None:
            return serialize_error(404, 'Invalid arguments')

        result = sctp_client.get_link_content(addr)
        if result is None:
            return serialize_error(404, 'Content not found')

        mimetype_str = u'text/plain'
        # determine format and mimetype
        format = sctp_client.iterate_elements(
            SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F,
            addr,
            ScElementType.sc_type_arc_common | ScElementType.sc_type_const,
            ScElementType.sc_type_node | ScElementType.sc_type_const,
            ScElementType.sc_type_arc_pos_const_perm,
            keynode_nrel_format
        )
        if format is not None:
            # fetermine mimetype
            mimetype = sctp_client.iterate_elements(
                SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F,
                format[0][2],
                ScElementType.sc_type_arc_common | ScElementType.sc_type_const,
                ScElementType.sc_type_link,
                ScElementType.sc_type_arc_pos_const_perm,
                keynode_nrel_mimetype
            )
            if mimetype is not None:
                mime_value = sctp_client.get_link_content(mimetype[0][2])
                if mime_value is not None:
                    mimetype_str = mime_value

    return HttpResponse(result, mimetype_str + '; charset=UTF-8')
开发者ID:Gr1N,项目名称:sc-web,代码行数:44,代码来源:views.py

示例14: link_content

def link_content(request):
    result = '{}'

    sctp_client = new_sctp_client()

    keys = Keynodes(sctp_client)
    keynode_nrel_format = keys[KeynodeSysIdentifiers.nrel_format]
    keynode_nrel_mimetype = keys[KeynodeSysIdentifiers.nrel_mimetype]

    # parse arguments
    addr = ScAddr.parse_from_string(request.GET.get('addr', None))
    if addr is None:
        return serialize_error(404, 'Invalid arguments')

    result = sctp_client.get_link_content(addr)
    if result is None:
        return serialize_error(404, 'Content not found')

    return HttpResponse(result, get_link_mime(addr, keynode_nrel_format, keynode_nrel_mimetype, sctp_client) + '; charset=UTF-8')
开发者ID:bakhmetow,项目名称:repo,代码行数:19,代码来源:views.py

示例15: get

    def get(self):

        with SctpClientInstance() as sctp_client:
    
            keys = Keynodes(sctp_client)
            keynode_nrel_format = keys[KeynodeSysIdentifiers.nrel_format]
            keynode_nrel_mimetype = keys[KeynodeSysIdentifiers.nrel_mimetype]
        
            # parse arguments
            addr = ScAddr.parse_from_string(self.get_argument('addr', None))        
            if addr is None:
                return logic.serialize_error(self, 404, 'Invalid arguments')
        
            result = sctp_client.get_link_content(addr)
            if result is None:
                return logic.serialize_error(self, 404, 'Content not found')
        
            self.set_header("Content-Type", logic.get_link_mime(addr, keynode_nrel_format, keynode_nrel_mimetype, sctp_client))
            self.finish(result)
开发者ID:blrB,项目名称:sc-web,代码行数:19,代码来源:api.py


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