def main(self): while 1: if self.dataReady("control"): mes = self.recv("control") if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): self.send(producerFinished(), "signal") break if self.dataReady("forward"): m = self.recv("forward") self.send(Message.to_element(m), "outbox") if self.dataReady("inbox"): handled = False e = self.recv("inbox") self.send(('INCOMING', e), "log") msg_type = e.get_attribute_value(u'type') or 'normal' key = 'xmpp.%s' % unicode(msg_type) if key in self.outboxes: self.send(Message.from_element(e), key) handled = True if not handled: self.send(e, "unknown") if not self.anyReady(): self.pause() yield 1
def main(self): yield self.initComponents() while 1: while self.dataReady("control"): mes = self.recv("control") if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): self.send(producerFinished(), "signal") break while self.dataReady("jid"): self.from_jid = self.recv('jid') while self.dataReady("inbox"): m = self.recv("inbox") # in this first case, we want to send the message # typed in the console. # The message is of the form: # contant_jid message if isinstance(m, (str, unicode)) and m != '': #print self.name + ' received string!' try: contact_jid, message = m.split(' ', 1) except ValueError: print "Messages format: contact_jid message" continue m = Message(unicode(self.from_jid), unicode(contact_jid), type=u'chat', stanza_id=generate_unique()) m.event = Event.composing # note the composing event status m.bodies.append(Body(unicode(message))) self.send(m, "outbox") # Right after we sent the first message # we send another one reseting the event status m = Message(unicode(self.from_jid), unicode(contact_jid), type=u'chat', stanza_id=generate_unique()) self.send(m, "outbox") # In this case we actually received a message # from a contact, we print it. elif isinstance(m, Message): #b_list = [str(body) for body in m.bodies] #abody = ''.join(b_list) #print 'body = ', abody self.send(m, 'proto') else: print 'unknown instance received!' if not self.anyReady(): self.pause() yield 1
def main(self): yield self.initComponents() while 1: if self.dataReady("control"): mes = self.recv("control") if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): self.send(producerFinished(), "signal") break if self.dataReady("jid"): self.from_jid = self.recv('jid') if self.dataReady("roster-received"): self.roster = self.recv("roster-received") if self.dataReady("inbox"): m = self.recv("inbox") if isinstance(m, str) and m != '': pass # In this case we actually received a message # from a contact, we print it. elif isinstance(m, Message): for body in m.bodies: message = remove_BOM(body.plain_body).strip() print "Received message: %s" % repr(message) try: action, data = message.split(' ', 1) except ValueError: action = 'PI' data = message if action in self.outboxes: self.send(data, action) if self.roster: for nodeid in self.roster.items: m = Message(unicode(self.from_jid), unicode(nodeid), type=u'chat', stanza_id=generate_unique()) m.event = Event.composing m.bodies.append(Body(unicode(data))) self.send(m, "outbox") if not self.anyReady(): self.pause() yield 1
def main(self): while 1: if self.dataReady("control"): mes = self.recv("control") if isinstance(mes, shutdownMicroprocess) or isinstance(mes, producerFinished): self.send(producerFinished(), "signal") break if self.dataReady("inbox"): m = self.recv("inbox") if m.bodies or m.subjects: m.swap_jids() self.send(Message.to_element(m), "outbox") if not self.anyReady(): self.pause() yield 1