changeset c7616f24c4fa in /home/hg/repos/gajim
branches: gtk3 details:http://hg.gajim.org/gajim?cmd=changeset;node=c7616f24c4fa description: move ConnectionPEP class to connection_handlers to prevent import loop
diffstat:
src/common/connection_handlers.py | 167 +++++++++++++++++++- src/common/pep.py | 169 +------------------- src/common/zeroconf/connection_handlers_zeroconf.py | 6 +- 3 files changed, 170 insertions(+), 172 deletions(-)
diffs (truncated from 384 to 300 lines):
diff -r c7223427f25d -r c7616f24c4fa src/common/connection_handlers.py --- a/src/common/connection_handlers.py Fri Apr 05 21:35:39 2013 +0200 +++ b/src/common/connection_handlers.py Sat Apr 06 10:14:28 2013 +0200 @@ -48,7 +48,6 @@ from common import jingle_xtls from common.commands import ConnectionCommands from common.pubsub import ConnectionPubSub -from common.pep import ConnectionPEP from common.protocol.caps import ConnectionCaps from common.protocol.bytestream import ConnectionSocks5Bytestream from common.protocol.bytestream import ConnectionIBBytestream @@ -767,6 +766,172 @@ p = self.add_sha(p) self.connection.send(p)
+ +class ConnectionPEP(object): + + def __init__(self, account, dispatcher, pubsub_connection): + self._account = account + self._dispatcher = dispatcher + self._pubsub_connection = pubsub_connection + self.reset_awaiting_pep() + + def pep_change_account_name(self, new_name): + self._account = new_name + + def reset_awaiting_pep(self): + self.to_be_sent_activity = None + self.to_be_sent_mood = None + self.to_be_sent_tune = None + self.to_be_sent_nick = None + self.to_be_sent_location = None + + def send_awaiting_pep(self): + """ + Send pep info that were waiting for connection + """ + if self.to_be_sent_activity: + self.send_activity(*self.to_be_sent_activity) + if self.to_be_sent_mood: + self.send_mood(*self.to_be_sent_mood) + if self.to_be_sent_tune: + self.send_tune(*self.to_be_sent_tune) + if self.to_be_sent_nick: + self.send_nick(self.to_be_sent_nick) + if self.to_be_sent_location: + self.send_location(self.to_be_sent_location) + self.reset_awaiting_pep() + + def _pubsubEventCB(self, xmpp_dispatcher, msg): + ''' Called when we receive <message /> with pubsub event. ''' + gajim.nec.push_incoming_event(PEPReceivedEvent(None, conn=self, + stanza=msg)) + + def send_activity(self, activity, subactivity=None, message=None): + if self.connected == 1: + # We are connecting, keep activity in mem and send it when we'll be + # connected + self.to_be_sent_activity = (activity, subactivity, message) + return + if not self.pep_supported: + return + item = nbxmpp.Node('activity', {'xmlns': nbxmpp.NS_ACTIVITY}) + if activity: + i = item.addChild(activity) + if subactivity: + i.addChild(subactivity) + if message: + i = item.addChild('text') + i.addData(message) + self._pubsub_connection.send_pb_publish('', nbxmpp.NS_ACTIVITY, item, + '0') + + def retract_activity(self): + if not self.pep_supported: + return + self.send_activity(None) + # not all client support new XEP, so we still retract + self._pubsub_connection.send_pb_retract('', nbxmpp.NS_ACTIVITY, '0') + + def send_mood(self, mood, message=None): + if self.connected == 1: + # We are connecting, keep mood in mem and send it when we'll be + # connected + self.to_be_sent_mood = (mood, message) + return + if not self.pep_supported: + return + item = nbxmpp.Node('mood', {'xmlns': nbxmpp.NS_MOOD}) + if mood: + item.addChild(mood) + if message: + i = item.addChild('text') + i.addData(message) + self._pubsub_connection.send_pb_publish('', nbxmpp.NS_MOOD, item, '0') + + def retract_mood(self): + if not self.pep_supported: + return + self.send_mood(None) + # not all client support new XEP, so we still retract + self._pubsub_connection.send_pb_retract('', nbxmpp.NS_MOOD, '0') + + def send_tune(self, artist='', title='', source='', track=0, length=0, + items=None): + if self.connected == 1: + # We are connecting, keep tune in mem and send it when we'll be + # connected + self.to_be_sent_tune = (artist, title, source, track, length, items) + return + if not self.pep_supported: + return + item = nbxmpp.Node('tune', {'xmlns': nbxmpp.NS_TUNE}) + if artist: + i = item.addChild('artist') + i.addData(artist) + if title: + i = item.addChild('title') + i.addData(title) + if source: + i = item.addChild('source') + i.addData(source) + if track: + i = item.addChild('track') + i.addData(track) + if length: + i = item.addChild('length') + i.addData(length) + if items: + item.addChild(payload=items) + self._pubsub_connection.send_pb_publish('', nbxmpp.NS_TUNE, item, '0') + + def retract_tune(self): + if not self.pep_supported: + return + self.send_tune(None) + # not all client support new XEP, so we still retract + self._pubsub_connection.send_pb_retract('', nbxmpp.NS_TUNE, '0') + + def send_nickname(self, nick): + if self.connected == 1: + # We are connecting, keep nick in mem and send it when we'll be + # connected + self.to_be_sent_nick = nick + return + if not self.pep_supported: + return + item = nbxmpp.Node('nick', {'xmlns': nbxmpp.NS_NICK}) + item.addData(nick) + self._pubsub_connection.send_pb_publish('', nbxmpp.NS_NICK, item, '0') + + def retract_nickname(self): + if not self.pep_supported: + return + self.send_nickname(None) + # not all client support new XEP, so we still retract + self._pubsub_connection.send_pb_retract('', nbxmpp.NS_NICK, '0') + + def send_location(self, info): + if self.connected == 1: + # We are connecting, keep location in mem and send it when we'll be + # connected + self.to_be_sent_location = info + return + if not self.pep_supported: + return + item = nbxmpp.Node('geoloc', {'xmlns': nbxmpp.NS_LOCATION}) + for field in LOCATION_DATA: + if info.get(field, None): + i = item.addChild(field) + i.addData(info[field]) + self._pubsub_connection.send_pb_publish('', nbxmpp.NS_LOCATION, item, '0') + + def retract_location(self): + if not self.pep_supported: + return + self.send_location({}) + # not all client support new XEP, so we still retract + self._pubsub_connection.send_pb_retract('', nbxmpp.NS_LOCATION, '0') + # basic connection handlers used here and in zeroconf class ConnectionHandlersBase: def __init__(self): diff -r c7223427f25d -r c7616f24c4fa src/common/pep.py --- a/src/common/pep.py Fri Apr 05 21:35:39 2013 +0200 +++ b/src/common/pep.py Sat Apr 06 10:14:28 2013 +0200 @@ -473,171 +473,4 @@
SUPPORTED_PERSONAL_USER_EVENTS = [UserMoodPEP, UserTunePEP, UserActivityPEP, - UserNicknamePEP, UserLocationPEP] - -from common.connection_handlers_events import PEPReceivedEvent - -class ConnectionPEP(object): - - def __init__(self, account, dispatcher, pubsub_connection): - self._account = account - self._dispatcher = dispatcher - self._pubsub_connection = pubsub_connection - self.reset_awaiting_pep() - - def pep_change_account_name(self, new_name): - self._account = new_name - - def reset_awaiting_pep(self): - self.to_be_sent_activity = None - self.to_be_sent_mood = None - self.to_be_sent_tune = None - self.to_be_sent_nick = None - self.to_be_sent_location = None - - def send_awaiting_pep(self): - """ - Send pep info that were waiting for connection - """ - if self.to_be_sent_activity: - self.send_activity(*self.to_be_sent_activity) - if self.to_be_sent_mood: - self.send_mood(*self.to_be_sent_mood) - if self.to_be_sent_tune: - self.send_tune(*self.to_be_sent_tune) - if self.to_be_sent_nick: - self.send_nick(self.to_be_sent_nick) - if self.to_be_sent_location: - self.send_location(self.to_be_sent_location) - self.reset_awaiting_pep() - - def _pubsubEventCB(self, xmpp_dispatcher, msg): - ''' Called when we receive <message /> with pubsub event. ''' - gajim.nec.push_incoming_event(PEPReceivedEvent(None, conn=self, - stanza=msg)) - - def send_activity(self, activity, subactivity=None, message=None): - if self.connected == 1: - # We are connecting, keep activity in mem and send it when we'll be - # connected - self.to_be_sent_activity = (activity, subactivity, message) - return - if not self.pep_supported: - return - item = nbxmpp.Node('activity', {'xmlns': nbxmpp.NS_ACTIVITY}) - if activity: - i = item.addChild(activity) - if subactivity: - i.addChild(subactivity) - if message: - i = item.addChild('text') - i.addData(message) - self._pubsub_connection.send_pb_publish('', nbxmpp.NS_ACTIVITY, item, - '0') - - def retract_activity(self): - if not self.pep_supported: - return - self.send_activity(None) - # not all client support new XEP, so we still retract - self._pubsub_connection.send_pb_retract('', nbxmpp.NS_ACTIVITY, '0') - - def send_mood(self, mood, message=None): - if self.connected == 1: - # We are connecting, keep mood in mem and send it when we'll be - # connected - self.to_be_sent_mood = (mood, message) - return - if not self.pep_supported: - return - item = nbxmpp.Node('mood', {'xmlns': nbxmpp.NS_MOOD}) - if mood: - item.addChild(mood) - if message: - i = item.addChild('text') - i.addData(message) - self._pubsub_connection.send_pb_publish('', nbxmpp.NS_MOOD, item, '0') - - def retract_mood(self): - if not self.pep_supported: - return - self.send_mood(None) - # not all client support new XEP, so we still retract - self._pubsub_connection.send_pb_retract('', nbxmpp.NS_MOOD, '0') - - def send_tune(self, artist='', title='', source='', track=0, length=0, - items=None): - if self.connected == 1: - # We are connecting, keep tune in mem and send it when we'll be - # connected - self.to_be_sent_tune = (artist, title, source, track, length, items) - return - if not self.pep_supported: - return - item = nbxmpp.Node('tune', {'xmlns': nbxmpp.NS_TUNE}) - if artist: - i = item.addChild('artist') - i.addData(artist) - if title: - i = item.addChild('title') - i.addData(title) - if source: