From goat.kamal at gmail.com Fri Mar 5 00:17:33 2010 From: goat.kamal at gmail.com (goat kamal) Date: Thu, 4 Mar 2010 18:17:33 -0500 Subject: [PyXMPP] Maze of twisty corridors: MucRoomHandler, MucRoomUser, MucRoomState, MucRoomManager Message-ID: <14fd1ae01003041517n4bf1d455h7ccf12ff8d13cd20@mail.gmail.com> Hi all. Sorry to start out with such a basic set of questions. We're testing a new ejabberd cluster. I'm attempting to create a very simple script that will join a muc, post a few messages, then disconnect. I've been attempting to use pyxmpp.muc to do this little job. As I understand it from reading the docs at http://pyxmpp.jajcus.net/api/pyxmpp.jabber.muc-module.html, I need to establish a client connection, pass the client stream to a manager, create a handler and pass both handler and manager to a MucRoomState object, from which I should be able to send messages to a room. I'm (probably painfully obviously) a newbie with xmpp, so I'm probably missing something very basic. Any help at all would be appreciated. #!/usr/bin/env python # -*- coding: utf-8 -*- import time, logging from pyxmpp.all import JID from pyxmpp.jabber.all import Client from pyxmpp.jabber.muc import MucRoomHandler, MucRoomUser, MucRoomState, MucRoomManager logger=logging.getLogger() handler = logging.FileHandler( "room.log" ) formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") handler.setFormatter( formatter ) logger.addHandler(handler) logger.setLevel(logging.DEBUG) jid=JID("myjid at myserver.com/Home") password=u"secret" roomjid = JID( "testroom at myotherserver.com" ) c=Client( jid, password ) c.logger = logger c.connect() manager= MucRoomManager( c.stream ) manager.set_handlers() manager.logger = logger handler = MucRoomHandler() room = MucRoomState( manager, jid, roomjid, handler ) room.send_message( u"%s"%time.ctime() ) --------------------log---------------------- 2010-03-04 18:01:08,404 - pyxmpp.Client - DEBUG - Creating client stream: , auth_methods=['sasl:DIGEST-MD5', 'digest'] 2010-03-04 18:01:08,640 - pyxmpp.Stream.out - DEBUG - OUT: '\n' 2010-03-04 18:01:08,644 - pyxmpp.Stream.out - DEBUG - OUT: 'Thu Mar 4 18:01:08 2010' -------------- next part -------------- An HTML attachment was scrubbed... URL: From strufkin at gmail.com Wed Mar 17 14:25:46 2010 From: strufkin at gmail.com (Serg Truf) Date: Wed, 17 Mar 2010 15:25:46 +0200 Subject: [PyXMPP] Want to implement component - logger Message-ID: <4BA0D85A.6080007@gmail.com> HI, all! i want to implement component for ejabberd server, but can't get route messages, so see only Unknown stanzas how can i handle those 'Unknown' stanzas? i read that should reimplement route_stanza, but as i understand this runs only when i set process_all_stanzas=False and i can't found where i should set this i tryed directly in pyxmpp/jabberd/componentstream.py but no luck. please advice me or give me an vector in this. trying to use code of echocomponent.py here is output: IN: "" Unhandled 'Unknown' stanza: '' StreamTLSMixIn._read(), socket: StreamBase._read(), socket: Regards, Serg Truf From jajcus at jajcus.net Wed Mar 17 19:13:58 2010 From: jajcus at jajcus.net (Jacek Konieczny) Date: Wed, 17 Mar 2010 19:13:58 +0100 Subject: [PyXMPP] Want to implement component - logger In-Reply-To: <4BA0D85A.6080007@gmail.com> References: <4BA0D85A.6080007@gmail.com> Message-ID: <20100317181358.GC3798@lolek.nigdzie> On Wed, Mar 17, 2010 at 03:25:46PM +0200, Serg Truf wrote: > i want to implement component for ejabberd server, but can't get route > messages, so see only Unknown stanzas > > how can i handle those 'Unknown' stanzas? There is direct interface for that. > i read that should reimplement route_stanza, That is not quite true. route_stanza is supposed to be used for stanzas not addressed to your component. > please advice me or give me an vector in this. Override the process_stanza() method of the stream object. Not to bother with subclassing you can just use some Python magic and replace the attribute: class Something(...): ... orig_process_stanza = None def some_stream_setup(self): self.orig_process_stanza = stream.process_stanza stream.process_stanza = self.my_process_stanza def my_process_stanza(self, stanza): if stanza.stanza_type == "route": stanza = do_something_like_stripping_route() return self.orig_process_stanza(stanza) I hope that helps (haven't tried it myself). Greets, Jacek