Пример #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)
Пример #2
0
 def __rpc_send(self, name, *args, **kwargs):
     log.info('run remote_method %s(%s, %s)' % (name, args, kwargs))
     rpc_request = RPCRequest(name, *args, **kwargs)
     self.client.send_message(self.remote_jid, rpc_request.dumps())
     response = self.__rpc_wait_response(rpc_request.id)
     if isinstance(response, Exception):
         raise response
     return response
Пример #3
0
 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
Пример #4
0
    def __init__(self, jid, password):
        super(ClientXMPP, self).__init__(jid, password)
        self.add_event_handler("session_start", self.session_start)
        self.add_event_handler("message", self.message_handler, threaded=True)
        self.load_plugin()

        self.remote_cmds = {}
        for name, value in inspect.getmembers(self, inspect.ismethod):
            if getattr(value, '_xmpp_remote', False):
                if name not in self.remote_cmds:
                    name = getattr(value, '__name__')
                    log.info('Registered remote method: %s' % name)
                    self.remote_cmds[name] = value

        self.response_queue = Queue()
        self.connect()
        self.process(Block=True)