Package emma :: Package interface :: Package xmpp
[hide private]
[frames] | no frames]

Source Code for Package emma.interface.xmpp

 1  """ 
 2  xmpp interface 
 3   
 4  @copyright: (c) 2011 hackmeeting U{http://sindominio.net/hackmeeting} 
 5  @author: Ales Zabala Alava (Shagi) 
 6  @organization: hackmeeting U{http://sindominio.net/hackmeeting} 
 7  @contact: shagi@gisa-elkartea.org 
 8  @license: 
 9    This program is free software; you can redistribute it and/or 
10    modify it under the terms of the Do What The Fuck You Want To 
11    Public License, Version 2, as published by Sam Hocevar. See 
12    U{http://sam.zoy.org/projects/COPYING.WTFPL} for more details. 
13  """ 
14   
15  from emma.interface import Interface 
16  from emma.events import Event, subscribe 
17   
18  from xmppclient import XMPPClient 
19   
20   
21 -class xmpp(Interface):
22 - def run(self):
23 event = Event(event='send', interface='xmpp', 24 identifier=self.identifier) 25 subscribe(event, self.handler) 26 27 jid = self.conf['jid'] 28 password = self.conf['password'] 29 server = self.conf['server'] 30 port = int(self.conf['port']) 31 self.log(_("Connect to jid: %(jid)s") % self.conf) 32 33 self.xmpp = XMPPClient(self.identifier, jid, password) 34 self.xmpp.register_plugin('xep_0030') # Service Discovery 35 self.xmpp.register_plugin('xep_0199') # XMPP Ping 36 if self.xmpp.connect((server, port)): 37 self.xmpp.process() 38 else: 39 self.log(_("error conecting to xmpp: %s") % jid)
40
41 - def handler(self, event, data):
42 if 'Subject' in data: 43 text = "%(Subject)s: %(Body)s" % data 44 else: 45 text = data['Body'] 46 self.xmpp.send_msg(data['To'], text)
47