Beispiel #1
0
 def message_handler(self, message):
     if (message['type'] not in ('chat', 'normal')
             or message['body'] == ''):
         return
     # try:
     rpc_message = RPCMessage.loads(message['body'])
     session = RPCSession(message, rpc_message)
     from robair_common import threadlocal
     threadlocal._rpc_session = session
     log.info("read rpc_message: %s" % rpc_message)
     if isinstance(rpc_message, RPCRequest):
         log.debug("cmd : %s :: args : %s :: kwargs : %s" %
                   (rpc_message.proc_name, rpc_message.args,
                    rpc_message.kwargs))
         if rpc_message.proc_name in self.remote_cmds:
             func = self.remote_cmds[rpc_message.proc_name]
             try:
                 args, kwargs = rpc_message.args, rpc_message.kwargs
                 result = func(*args, **kwargs)
                 rpc_response = RPCResponse(rpc_message.id, result)
             except Exception as e:
                 m = traceback.format_exc(e)
                 log.debug("An exception occurred : %s" % m)
                 exception = RemoteXMPPException(m)
                 rpc_response = RPCResponse(rpc_message.id, exception)
             self.send_message(session.client_jid, rpc_response.dumps())
     elif isinstance(rpc_message, RPCResponse):
         self.response_queue.put(rpc_message)
 def __rpc_ping(self):
     log.info("Try to ping %s" % self.remote_jid)
     result = self.client['xep_0199'].send_ping(self.remote_jid,
                                                timeout=5,
                                                errorfalse=True)
     log.debug("%s" % result)
     if not result:
         log.info("Couldn't ping %s" % self.remote_jid)
     else:
         return True