def register_callback(self, kind, function): self.register_handler( Callback( kind, MatchXPath( '{jabber:client}iq/{com:ctl}query/{com:ctl}ctl[@td="' + kind + '"]'), function))
def session_start(self, event): logging.debug("----------------- starting session ----------------") logging.debug("event = {}".format(event)) self.register_handler(Callback("general", MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}'), self._handle_ctl)) self.ready_flag.set()
def connect(self, jid, password): self.jid = jid if self.connection == None: self.connection = ClientXMPP(jid, password) register_stanza_plugin(Message, WylioStanza) register_stanza_plugin(WylioStanza, ValueStanza) self.connection.add_event_handler("connected", self.connected) self.connection.add_event_handler("session_start", self.start) self.connection.add_event_handler("failed_auth", self.failed) self.connection.add_event_handler("disconnected", self.disconnected) self.connection.add_event_handler("message", self.message) self.connection.register_handler( Callback("Wylio", StanzaPath("message/wylio"), self.message_wylio)) self.connection.connect(('talk.google.com', 5222)) self.connection.process()
def connect(self,jid,password): if self.connection == None: self.connection = ClientXMPP(jid, password) register_stanza_plugin (Message, WylioStanza) register_stanza_plugin (WylioStanza, ValueStanza) self.connection.add_event_handler("connected", self.connected) self.connection.add_event_handler("disconnected", self.disconnected) self.connection.add_event_handler("failed_auth", self.failed_auth) self.connection.add_event_handler("session_start", self.start) self.connection.add_event_handler("message", self.message) self.connection.register_handler(Callback("Wylio", StanzaPath("message/wylio"), self.message_wylio)) print "connect" self.connection.connect() self.connection.process(block=True) print "connected"
def testtransport_send_message(self, msg_mock): """ Test to check the send message method of transport instance of the signal class. """ register_stanza_plugin(Message, IpopSignal) sig_dict, signal = self.setup_vars_mocks() transport = XmppTransport.factory( "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal, signal._presence_publisher, None, None) transport.registerHandler( Callback("ipop", StanzaPath("message/ipop"), transport.message_listener)) msg = transport.Message() msg_mock.return_value = msg msg.send = MagicMock() transport.send_msg("2", "invk", "Data") msg.send.assert_called_once() print("Passed : testtransport_send_message")
def testCallback(self): """Test using stream callback handlers.""" def callback_handler(stanza): self.xmpp.send_raw(""" <message> <body>Success!</body> </message> """) callback = Callback('Test Callback', MatchXPath('{test}tester'), callback_handler) self.xmpp.register_handler(callback) self.recv("""<tester xmlns="test" />""") msg = self.Message() msg['body'] = 'Success!' self.send(msg)