本文整理汇总了Python中sctp.types.ScAddr.parse_from_string方法的典型用法代码示例。如果您正苦于以下问题:Python ScAddr.parse_from_string方法的具体用法?Python ScAddr.parse_from_string怎么用?Python ScAddr.parse_from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sctp.types.ScAddr
的用法示例。
在下文中一共展示了ScAddr.parse_from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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))
示例2: info_tooltip
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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')
示例3: post
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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()
示例4: set_language
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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')
示例5: link_content
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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')
示例6: link_content
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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')
示例7: get
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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)
示例8: link_format
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
def link_format(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 = ScAddr.parse_from_string(request.POST.get(arg_str, None))
if arg is not None:
arguments.append(arg)
first = False
idx += 1
keys = Keynodes(sctp_client)
keynode_nrel_format = keys[KeynodeSysIdentifiers.nrel_format]
keynode_format_txt = keys[KeynodeSysIdentifiers.format_txt]
result = {}
for arg in arguments:
# try to resolve format
format = sctp_client.iterate_elements(
SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F,
arg,
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:
result[arg.to_id()] = format[0][2].to_id()
else:
result[arg.to_id()] = keynode_format_txt.to_id()
result = json.dumps(result)
return HttpResponse(result, 'application/json')
示例9: idtf_resolve
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
def idtf_resolve(request):
result = None
if request.is_ajax():
# get arguments
idx = 1
arguments = []
arg = ''
while arg is not None:
arg = request.POST.get(u'%d_' % idx, None)
if arg is not None:
arguments.append(arg)
idx += 1
sctp_client = new_sctp_client()
keys = Keynodes(sctp_client)
sc_session = logic.ScSession(request.user, request.session, sctp_client, keys)
used_lang = sc_session.get_used_language()
result = {}
# get requested identifiers for arguments
for addr_str in arguments:
addr = ScAddr.parse_from_string(addr_str)
if addr is None:
print 'Can\'t parse sc-addr from argument: %s' % addr_str
return serialize_error(404, 'Can\'t parse sc-addr from argument: %s' % addr_str)
found = False
idtf_value = get_identifier_translated(addr, used_lang, keys, sctp_client)
if idtf_value:
result[addr_str] = idtf_value
result = json.dumps(result)
return HttpResponse(result, 'application/json')
示例10: get_identifier
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
def get_identifier(request):
result = None
if request.is_ajax():
lang_code = ScAddr.parse_from_string(request.GET.get(u'language', None))
if lang_code is None:
print 'Invalid sc-addr of language'
return HttpResponse(None)
# get arguments
idx = 1
arguments = []
arg = ''
while arg is not None:
arg = request.GET.get(u'%d_' % idx, None)
if arg is not None:
arguments.append(arg)
idx += 1
sctp_client = new_sctp_client()
keys = Keynodes(sctp_client)
keynode_ui_nrel_idtf_language_relation = keys[KeynodeSysIdentifiers.ui_nrel_idtf_language_relation]
# first of all we need to resolve language relation
lang_relation_keynode = sctp_client.iterate_elements(
SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F,
lang_code,
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_ui_nrel_idtf_language_relation
)
if lang_relation_keynode is None:
print 'Can\'t resolve keynode for language "%s"' % str(lang_code)
return HttpResponse(None)
lang_relation_keynode = lang_relation_keynode[0][2]
result = {}
# get requested identifiers for arguments
for addr_str in arguments:
addr = ScAddr.parse_from_string(addr_str)
if addr is None:
print 'Can\'t parse sc-addr from argument: %s' % addr_str
return serialize_error(404, 'Can\'t parse sc-addr from argument: %s' % addr_str)
identifier = 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_link,
ScElementType.sc_type_arc_pos_const_perm,
lang_relation_keynode
)
idtf_value = None
if identifier is not None:
idtf_addr = identifier[0][2]
# get identifier value
idtf_value = sctp_client.get_link_content(idtf_addr)
idtf_value = idtf_value.decode('utf-8')
result[addr_str] = idtf_value
result = json.dumps(result)
return HttpResponse(result, 'application/json')
示例11: post
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
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 serialize_error(404, "Invalid argument: %s" % arg)
first = False
idx += 1
if (len(arguments) > 0) and (cmd_addr is not None):
keys = Keynodes(sctp_client)
keynode_ui_rrel_commnad = keys[KeynodeSysIdentifiers.ui_rrel_commnad]
keynode_ui_rrel_command_arguments = keys[KeynodeSysIdentifiers.ui_rrel_command_arguments]
keynode_ui_nrel_command_result = keys[KeynodeSysIdentifiers.ui_nrel_command_result]
keynode_ui_command_generate_instance = keys[KeynodeSysIdentifiers.ui_command_generate_instance]
keynode_ui_command_initiated = keys[KeynodeSysIdentifiers.ui_command_initiated]
keynode_ui_command_finished = keys[KeynodeSysIdentifiers.ui_command_finished]
keynode_ui_nrel_command_result = keys[KeynodeSysIdentifiers.ui_nrel_command_result]
keynode_ui_user = keys[KeynodeSysIdentifiers.ui_user]
keynode_nrel_authors = keys[KeynodeSysIdentifiers.nrel_authors]
keynode_question_initiated = keys[KeynodeSysIdentifiers.question_initiated]
keynode_question = keys[KeynodeSysIdentifiers.question]
keynode_system_element = keys[KeynodeSysIdentifiers.system_element]
keynode_nrel_ui_nrel_command_lang_template = keys[KeynodeSysIdentifiers.nrel_ui_nrel_command_lang_template]
keynode_languages = keys[KeynodeSysIdentifiers.languages]
keynode_nrel_main_idtf = keys[KeynodeSysIdentifiers.nrel_main_idtf]
# create command in sc-memory
inst_cmd_addr = sctp_client.create_node(ScElementType.sc_type_node | ScElementType.sc_type_const)
logic.append_to_system_elements(sctp_client, keynode_system_element, inst_cmd_addr)
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_command_generate_instance, inst_cmd_addr)
logic.append_to_system_elements(sctp_client, keynode_system_element, arc)
inst_cmd_arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, inst_cmd_addr, cmd_addr)
logic.append_to_system_elements(sctp_client, keynode_system_element, inst_cmd_arc)
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_rrel_commnad, inst_cmd_arc)
logic.append_to_system_elements(sctp_client, keynode_system_element, arc)
# create arguments
args_addr = sctp_client.create_node(ScElementType.sc_type_node | ScElementType.sc_type_const)
logic.append_to_system_elements(sctp_client, keynode_system_element, args_addr)
args_arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, inst_cmd_addr, args_addr)
logic.append_to_system_elements(sctp_client, keynode_system_element, args_arc)
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_rrel_command_arguments, args_arc)
logic.append_to_system_elements(sctp_client, keynode_system_element, arc)
idx = 1
for arg in arguments:
arg_arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, args_addr, arg)
logic.append_to_system_elements(sctp_client, keynode_system_element, arg_arc)
if arg_arc is None:
return serialize_error(self, 404, 'Error while create "create_instance" command')
idx_addr = sctp_client.find_element_by_system_identifier(str(u'rrel_%d' % idx))
if idx_addr is None:
return serialize_error(self, 404, 'Error while create "create_instance" command')
idx += 1
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, idx_addr, arg_arc)
logic.append_to_system_elements(sctp_client, keynode_system_element, arc)
wait_time = 0
wait_dt = 0.1
# initialize command
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_command_initiated, inst_cmd_addr)
cmd_finished = logic.check_command_finished(inst_cmd_addr, keynode_ui_command_finished, sctp_client)
while cmd_finished is None:
time.sleep(wait_dt)
wait_time += wait_dt
if wait_time > tornado.options.options.event_wait_timeout:
return serialize_error(self, 404, 'Timeout waiting for "create_instance" command finished')
cmd_finished = logic.check_command_finished(inst_cmd_addr, keynode_ui_command_finished, sctp_client)
# get command result
cmd_result = sctp_client.iterate_elements(
SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F,
inst_cmd_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_ui_nrel_command_result
)
if cmd_result is None:
#.........这里部分代码省略.........
示例12: idtf_resolve
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
def idtf_resolve(request):
result = None
if request.is_ajax():
# get arguments
idx = 1
arguments = []
arg = ''
while arg is not None:
arg = request.POST.get(u'%d_' % idx, None)
if arg is not None:
arguments.append(arg)
idx += 1
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]
sc_session = logic.ScSession(request.user, request.session, sctp_client, keys)
used_lang = sc_session.get_used_language()
result = {}
# get requested identifiers for arguments
for addr_str in arguments:
addr = ScAddr.parse_from_string(addr_str)
if addr is None:
print 'Can\'t parse sc-addr from argument: %s' % addr_str
return serialize_error(404, 'Can\'t parse sc-addr from argument: %s' % addr_str)
found = False
identifier = 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_link,
ScElementType.sc_type_arc_pos_const_perm,
keynode_nrel_main_idtf
)
idtf_value = None
if identifier is not None:
for res in identifier:
idtf_addr = res[2]
# check if founded main identifier is for used language
langs = sctp_client.iterate_elements(
SctpIteratorType.SCTP_ITERATOR_3F_A_F,
used_lang,
ScElementType.sc_type_arc_pos_const_perm,
idtf_addr
)
if langs is not None:
# get identifier value
idtf_value = sctp_client.get_link_content(idtf_addr)
idtf_value = idtf_value.decode('utf-8')
found = True
result[addr_str] = idtf_value
# if identifier not found, then get system identifier
if not found:
identifier = 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_link,
ScElementType.sc_type_arc_pos_const_perm,
keynode_nrel_system_identifier
)
if identifier is not None:
idtf_value = sctp_client.get_link_content(identifier[0][2])
idtf_value = idtf_value.decode('utf-8')
result[addr_str] = idtf_value
result = json.dumps(result)
return HttpResponse(result, 'application/json')
示例13: question_answer_translate
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
def question_answer_translate(request):
if request.is_ajax():
sctp_client = new_sctp_client()
question_addr = ScAddr.parse_from_string(request.POST.get(u'question', None))
format_addr = ScAddr.parse_from_string(request.POST.get(u'format', None))
keys = Keynodes(sctp_client)
keynode_nrel_answer = keys[KeynodeSysIdentifiers.question_nrel_answer]
keynode_nrel_translation = keys[KeynodeSysIdentifiers.nrel_translation]
keynode_nrel_format = keys[KeynodeSysIdentifiers.nrel_format]
keynode_system_element = keys[KeynodeSysIdentifiers.system_element]
# try to find answer for the question
wait_time = 0
wait_dt = 0.1
answer = find_answer(question_addr, keynode_nrel_answer, sctp_client)
while answer is None:
time.sleep(wait_dt)
wait_time += wait_dt
if wait_time > settings.EVENT_WAIT_TIMEOUT:
return serialize_error(404, 'Timeout waiting for answer')
answer = find_answer(question_addr, keynode_nrel_answer, sctp_client)
if answer is None:
return serialize_error(404, 'Answer not found')
answer_addr = answer[0][2]
result_link_addr = None
# try to find translation to specified format
result_link_addr = find_translation_with_format(answer_addr, format_addr, keynode_nrel_format, keynode_nrel_translation, sctp_client)
# if link addr not found, then run translation of answer to specified format
if result_link_addr is None:
trans_cmd_addr = sctp_client.create_node(ScElementType.sc_type_node | ScElementType.sc_type_const)
append_to_system_elements(sctp_client, keynode_system_element, trans_cmd_addr)
arc_addr = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, trans_cmd_addr, answer_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc_addr)
arc_addr = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keys[KeynodeSysIdentifiers.ui_rrel_source_sc_construction], arc_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc_addr)
arc_addr = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, trans_cmd_addr, format_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc_addr)
arc_addr = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keys[KeynodeSysIdentifiers.ui_rrel_output_format], arc_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc_addr)
# add into translation command set
arc_addr = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keys[KeynodeSysIdentifiers.ui_command_translate_from_sc], trans_cmd_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc_addr)
# initialize command
arc_addr = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keys[KeynodeSysIdentifiers.ui_command_initiated], trans_cmd_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc_addr)
# now we need to wait translation result
wait_time = 0
translation = find_translation_with_format(answer_addr, format_addr, keynode_nrel_format, keynode_nrel_translation, sctp_client)
while translation is None:
time.sleep(wait_dt)
wait_time += wait_dt
if wait_time > settings.EVENT_WAIT_TIMEOUT:
return serialize_error(404, 'Timeout waiting for answer translation')
translation = find_translation_with_format(answer_addr, format_addr, keynode_nrel_format, keynode_nrel_translation, sctp_client)
if translation is not None:
result_link_addr = translation
# if result exists, then we need to return it content
if result_link_addr is not None:
result = json.dumps({"link": result_link_addr.to_id()})
return HttpResponse(result, 'application/json')
return serialize_error(404, "Can't make translation")
示例14: cmd_do
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
def cmd_do(request):
result = '[]'
if request.is_ajax():
sctp_client = new_sctp_client()
cmd_addr = ScAddr.parse_from_string(request.POST.get(u'cmd', None))
# parse arguments
first = True
arg = None
arguments = []
idx = 0
while first or (arg is not None):
arg = ScAddr.parse_from_string(request.POST.get(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 serialize_error(404, "Invalid argument: %s" % arg)
first = False
idx += 1
if (len(arguments) > 0) and (cmd_addr is not None):
keys = Keynodes(sctp_client)
keynode_ui_rrel_commnad = keys[KeynodeSysIdentifiers.ui_rrel_commnad]
keynode_ui_rrel_command_arguments = keys[KeynodeSysIdentifiers.ui_rrel_command_arguments]
keynode_ui_nrel_command_result = keys[KeynodeSysIdentifiers.ui_nrel_command_result]
keynode_ui_user_command_question = keys[KeynodeSysIdentifiers.ui_user_command_question]
keynode_ui_command_generate_instance = keys[KeynodeSysIdentifiers.ui_command_generate_instance]
keynode_ui_command_initiated = keys[KeynodeSysIdentifiers.ui_command_initiated]
keynode_ui_command_finished = keys[KeynodeSysIdentifiers.ui_command_finished]
keynode_ui_nrel_command_result = keys[KeynodeSysIdentifiers.ui_nrel_command_result]
keynode_ui_user = keys[KeynodeSysIdentifiers.ui_user]
#keynode_ui_displayed_answer = keys[KeynodeSysIdentifiers.ui_displayed_answer]
keynode_nrel_authors = keys[KeynodeSysIdentifiers.nrel_authors]
#keynode_ui_nrel_user_answer_formats = keys[KeynodeSysIdentifiers.ui_nrel_user_answer_formats]
#keynode_nrel_translation = keys[KeynodeSysIdentifiers.nrel_translation]
#keynode_nrel_answer = keys[KeynodeSysIdentifiers.question_nrel_answer]
keynode_question_initiated = keys[KeynodeSysIdentifiers.question_initiated]
keynode_question = keys[KeynodeSysIdentifiers.question]
keynode_system_element = keys[KeynodeSysIdentifiers.system_element]
# create command in sc-memory
inst_cmd_addr = sctp_client.create_node(ScElementType.sc_type_node | ScElementType.sc_type_const)
append_to_system_elements(sctp_client, keynode_system_element, inst_cmd_addr)
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_command_generate_instance, inst_cmd_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc)
inst_cmd_arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, inst_cmd_addr, cmd_addr)
append_to_system_elements(sctp_client, keynode_system_element, inst_cmd_arc)
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_rrel_commnad, inst_cmd_arc)
append_to_system_elements(sctp_client, keynode_system_element, arc)
# create arguments
args_addr = sctp_client.create_node(ScElementType.sc_type_node | ScElementType.sc_type_const)
append_to_system_elements(sctp_client, keynode_system_element, args_addr)
args_arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, inst_cmd_addr, args_addr)
append_to_system_elements(sctp_client, keynode_system_element, args_arc)
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_rrel_command_arguments, args_arc)
append_to_system_elements(sctp_client, keynode_system_element, arc)
idx = 1
for arg in arguments:
arg_arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, args_addr, arg)
append_to_system_elements(sctp_client, keynode_system_element, arg_arc)
if arg_arc is None:
return serialize_error(404, 'Error while create "create_instance" command')
idx_addr = sctp_client.find_element_by_system_identifier(str(u'rrel_%d' % idx))
if idx_addr is None:
return serialize_error(404, 'Error while create "create_instance" command')
idx += 1
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, idx_addr, arg_arc)
append_to_system_elements(sctp_client, keynode_system_element, arc)
wait_time = 0
wait_dt = 0.1
# initialize command
arc = sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm, keynode_ui_command_initiated, inst_cmd_addr)
append_to_system_elements(sctp_client, keynode_system_element, arc)
cmd_finished = check_command_finished(inst_cmd_addr, keynode_ui_command_finished, sctp_client)
while cmd_finished is None:
time.sleep(wait_dt)
wait_time += wait_dt
if wait_time > settings.EVENT_WAIT_TIMEOUT:
return serialize_error(404, 'Timeout waiting for "create_instance" command finished')
cmd_finished = check_command_finished(inst_cmd_addr, keynode_ui_command_finished, sctp_client)
# get command result
cmd_result = sctp_client.iterate_elements(
SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F,
inst_cmd_addr,
ScElementType.sc_type_arc_common | ScElementType.sc_type_const,
ScElementType.sc_type_node | ScElementType.sc_type_const,
#.........这里部分代码省略.........
示例15: send
# 需要导入模块: from sctp.types import ScAddr [as 别名]
# 或者: from sctp.types.ScAddr import parse_from_string [as 别名]
def send(self, message):
cmd = json.loads(message)
cmdCode = cmd['cmdCode']
def response_message(resCode, res):
if res is not None:
r = res
if isinstance(res, ScAddr):
r = res.to_id()
self.on_message(json.dumps({'resCode': resCode, 'result': r}))
else:
self.on_message(json.dumps({'resCode': resCode}))
def res_code(res):
if res is not None:
return sctp.types.SctpResultCode.SCTP_RESULT_OK
return sctp.types.SctpResultCode.SCTP_RESULT_FAIL
if cmdCode == sctp.types.SctpCommandType.SCTP_CMD_CHECK_ELEMENT:
response_message(res_code(sctp.types.ScAddr.parse_from_string(cmd['args'][0])), None)
elif cmdCode == sctp.types.SctpCommandType.SCTP_CMD_FIND_ELEMENT_BY_SYSITDF:
res = self.sctp_client.find_element_by_system_identifier(str(cmd['args'][0]))
response_message(res_code(res), res)
elif cmdCode == sctp.types.SctpCommandType.SCTP_CMD_GET_ELEMENT_TYPE:
res = self.sctp_client.get_element_type(sctp.types.ScAddr.parse_from_string(cmd['args'][0]))
response_message(res_code(res), res)
elif cmdCode == sctp.types.SctpCommandType.SCTP_CMD_GET_ARC:
res = self.sctp_client.get_arc(sctp.types.ScAddr.parse_from_string(cmd['args'][0]))
response_message(res_code(res), [res[0].to_id(), res[1].to_id()])
elif cmdCode == sctp.types.SctpCommandType.SCTP_CMD_GET_LINK_CONTENT:
res = self.sctp_client.get_link_content(sctp.types.ScAddr.parse_from_string(cmd['args'][0]))
response_message(res_code(res), res)
elif cmdCode == sctp.types.SctpCommandType.SCTP_CMD_ITERATE_ELEMENTS:
resCode = sctp.types.SctpResultCode.SCTP_RESULT_FAIL
res = None
itType = cmd['args'][0]
args = cmd['args'][1:]
if itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_3A_A_F:
res = self.sctp_client.iterate_elements(itType,
args[0], args[1],
sctp.types.ScAddr.parse_from_string(args[2]))
elif itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_3F_A_A:
res = self.sctp_client.iterate_elements(itType,
sctp.types.ScAddr.parse_from_string(args[0]),
args[1],
args[2])
elif itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_3F_A_F:
res = self.sctp_client.iterate_elements(itType,
sctp.types.ScAddr.parse_from_string(args[0]),
args[1],
sctp.types.ScAddr.parse_from_string(args[2]))
elif itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_5_A_A_F_A_A:
res = self.sctp_client.iterate_elements(itType,
args[0],
args[1],
sctp.types.ScAddr.parse_from_string(args[2]),
args[3],
args[4])
elif itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_5_A_A_F_A_F:
res = self.sctp_client.iterate_elements(itType,
args[0],
args[1],
sctp.types.ScAddr.parse_from_string(args[2]),
args[3],
sctp.types.ScAddr.parse_from_string(args[4]))
elif itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_5_F_A_A_A_A:
res = self.sctp_client.iterate_elements(itType,
sctp.types.ScAddr.parse_from_string(args[0]),
args[1],
args[2],
args[3],
args[4])
elif itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_5_F_A_F_A_A:
res = self.sctp_client.iterate_elements(itType,
sctp.types.ScAddr.parse_from_string(args[0]),
args[1],
sctp.types.ScAddr.parse_from_string(args[2]),
args[3],
args[4])
elif itType == sctp.types.SctpIteratorType.SCTP_ITERATOR_5_F_A_F_A_F:
res = self.sctp_client.iterate_elements(itType,
sctp.types.ScAddr.parse_from_string(args[0]),
args[1],
#.........这里部分代码省略.........