1
2 import empro.core
3 import xml.dom
4 import xml.dom.minidom
5
6
8 text = []
9 for n in node.childNodes:
10 if n.nodeType in (xml.dom.Node.TEXT_NODE, xml.dom.Node.CDATA_SECTION_NODE):
11 text.append(n.data)
12 return ''.join(text)
13
14
16 if element.tagName == "null":
17 return None
18 elif element.tagName == "int":
19 return int(_getText(element))
20 elif element.tagName == "real":
21 return float(_getText(element))
22 elif element.tagName == "string":
23 return _getText(element)
24 elif element.tagName == "list":
25 result = []
26 for listItem in element.childNodes:
27 if listItem.nodeType == xml.dom.Node.ELEMENT_NODE:
28 result.append(_convertElementToPython(listItem))
29 return result
30 else:
31 raise RuntimeError("callRpcMethod: unsupported result data type <%s>" % element.tagName)
32
33
35 if value is None:
36 parentElement.appendChild(doc.createElement("null"))
37 elif isinstance(value, (int, long)):
38 parentElement.appendChild(doc.createElement("int")).appendChild(doc.createTextNode(str(long(value))))
39 elif isinstance(value, float):
40 parentElement.appendChild(doc.createElement("real")).appendChild(doc.createTextNode(str(value)))
41 elif isinstance(value, basestring):
42 parentElement.appendChild(doc.createElement("string")).appendChild(doc.createTextNode(value))
43 elif isinstance(value, list):
44 listElement = parentElement.appendChild(doc.createElement("list"))
45 for listItem in value:
46 _createElementFromPython(listItem, doc, listElement)
47 else:
48 raise RuntimeError("callRpcMethod: unsupported argument data type %s" % str(type(value)))
49
50
52 rpc = rpc or empro.core.CommunicationWithParent.rpc()
53 doc = xml.dom.minidom.Document()
54 callElement = doc.appendChild(doc.createElement("call"))
55 callElement.appendChild(doc.createElement("method")).appendChild(doc.createTextNode(methodName))
56 callElement.appendChild(doc.createElement("function")).appendChild(doc.createTextNode(function))
57 callElement.appendChild(doc.createElement("vocabulary")).appendChild(doc.createTextNode(vocabulary))
58 argsElement = callElement.appendChild(doc.createElement("args"))
59 for arg in argsList:
60 _createElementFromPython(arg, doc, argsElement)
61 reply = xml.dom.minidom.parseString(rpc.call(doc.toxml()).encode('utf-8'))
62 for replyElement in reply.childNodes:
63 if replyElement.nodeType == xml.dom.Node.ELEMENT_NODE:
64 for resultElement in replyElement.childNodes:
65 if resultElement.nodeType == xml.dom.Node.ELEMENT_NODE:
66 return _convertElementToPython(resultElement)
67 raise RuntimeError("%s: missing result in reply" % methodName)
68
69
70 -def callParent(function, argsList=(), vocabulary="CmdOp", rpc=None):
71 """
72 callParent(function, argsList = (), vocabulary = \"CmdOp\", rpc = empro.core.CommunicationWithParent.rpc()). Calls the Skill function and returns the result.
73 function: Skill function to call
74 argsList: Python tuple or list of arguments (default empty). Can contain None (= Parent NULL), integers, floats, strings and lists.
75 vocabulary: theParent vocabulary, or \"CmdOp\"
76 rpc: the EmSubprocessRpc object executing the call (defaults to empro.core.CommunicationWithParent.rpc())
77 """
78 return callRpcMethodBlockingOrNonBlocking("apply", function, argsList, vocabulary, rpc)
79
80
81 -def callAEL(function, argsList=(), vocabulary="CmdOp", rpc=None):
82 """
83 callAEL(function, argsList = (), vocabulary = \"CmdOp\", rpc = empro.core.CommunicationWithParent.rpc()). Calls the AEL function and returns the result.
84 function: AEL function to call
85 argsList: Python tuple or list of arguments (default empty). Can contain None (= AEL NULL), integers, floats, strings and lists.
86 vocabulary: theAEL vocabulary, or \"CmdOp\"
87 rpc: the EmSubprocessRpc object executing the call (defaults to empro.core.CommunicationWithParent.rpc())
88 """
89 return callRpcMethodBlockingOrNonBlocking("callAEL", function, argsList, vocabulary, rpc)
90
91
93 """
94 callAELNonBlocking(function, argsList = (), vocabulary = \"CmdOp\", rpc = empro.core.CommunicationWithParent.rpc()). Calls the AEL function without waiting for the result.
95 function: AEL function to call
96 argsList: Python tuple or list of arguments (default empty). Can contain None (= AEL NULL), integers, floats, strings and lists.
97 vocabulary: theAEL vocabulary, or \"CmdOp\"
98 rpc: the EmSubprocessRpc object executing the call (defaults to empro.core.CommunicationWithParent.rpc())
99 """
100 return callRpcMethodBlockingOrNonBlocking("callAELNonBlocking", function, argsList, vocabulary, rpc)
101
102
120