示例#1
0
def get_status(sock, server, node, uinput):
    what  = uinput[0]
    api   = "handle_call"
    status= pyerl.mk_atom("status")
    if  what == 'node':
        value = uinput[-1]
        val = pyerl.mk_atom(value)
    elif what == 'guid':
        value = uinput[-1]
        val = pyerl.mk_int(int(value))
    elif what == 'pid':
        rnode = uinput[1] # remote node
        pid   = uinput[2] # remote pid
        nodename = pyerl.mk_atom(rnode)
        ppid = pyerl.mk_string(pid)
        val   = pyerl.mk_tuple((nodename, ppid))
    else:
        raise Exception('Unknown message: %s' %  what)
    what  = pyerl.mk_atom(what)
    pid   = pyerl.mk_pid("node", 1, 2, 3)
    state = pyerl.mk_atom("atom") # passed state to server is irrelevant in this call
    tup   = pyerl.mk_tuple((status, what, val))
    args  = pyerl.mk_list([tup, pid, state])
    eterm = pyerl.rpc(sock, server, api, args)
    return eterm
 def test_mk_list(self):
     atom = eterm = pyerl.mk_atom("atom")
     integer = eterm = pyerl.mk_int(-1)
     string = eterm = pyerl.mk_string("string")
     eterm = pyerl.mk_tuple((atom, integer, string))
     self.assertEqual(eterm.is_tuple(), True);
     self.assertEqual(eterm.type, pyerl.TUPLE);
     self.assertEqual(str(eterm), "{atom, -1, \"string\"}");
 def test_mk_list(self):
     atom = eterm = pyerl.mk_atom("atom")
     integer = eterm = pyerl.mk_int(-1)
     string = eterm = pyerl.mk_string("string")
     eterm = pyerl.mk_list([atom, integer, string])
     self.assertEqual(eterm.is_list(), True);
     self.assertEqual(eterm.is_cons(), True);
     self.assertEqual(eterm.type, pyerl.LIST);
     self.assertEqual(str(eterm), "[atom, -1, \"string\"]");
 def test_mk_int(self):
     eterm = pyerl.mk_int(-1)
     self.assertEqual(eterm.type, pyerl.INTEGER);
     self.assertEqual(eterm.is_integer(), True);
     self.assertEqual(str(eterm), "-1");