From fb456b1ee4503bae02712e1b6b41aec4b028f382 Mon Sep 17 00:00:00 2001 From: Stephan Erb Date: Sun, 22 Nov 2009 22:57:52 +0100 Subject: [PATCH] Make dependencies of ConnectionPEP explicit. This means ConnectionPEP now knows the objects on which it calls method. Before, it just assumed that: "it will be subclassed and that the subclass defines a few methods". Big advantage is that false positives in the pylint report are gone --- src/common/connection_handlers.py | 2 ++ src/common/pep.py | 45 +++++++++++++++++-------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 15a979415..e8abbae74 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1458,6 +1458,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionBytestream.__init__(self) ConnectionCommands.__init__(self) ConnectionPubSub.__init__(self) + ConnectionPEP.__init__(self, account=self.name, dispatcher=self, + pubsub_connection=self) ConnectionJingle.__init__(self) ConnectionHandlersBase.__init__(self) self.gmail_url = None diff --git a/src/common/pep.py b/src/common/pep.py index 3437d4a46..34f3bda46 100644 --- a/src/common/pep.py +++ b/src/common/pep.py @@ -247,12 +247,12 @@ class AbstractPEP(object): acc.pep[self.type] = self def asPixbufIcon(self): - '''To be implemented by subclasses''' - raise NotImplementedError + '''SHOULD be implemented by subclasses''' + return None def asMarkupText(self): - '''To be implemented by subclasses''' - raise NotImplementedError + '''SHOULD be implemented by subclasses''' + return '' class UserMoodPEP(AbstractPEP): @@ -287,14 +287,14 @@ class UserMoodPEP(AbstractPEP): def asMarkupText(self): assert not self._retracted untranslated_mood = self._pep_specific_data['mood'] - mood = _translate_mood(untranslated_mood) + mood = self._translate_mood(untranslated_mood) markuptext = '%s' % gobject.markup_escape_text(mood) if 'text' in self._pep_specific_data: text = self._pep_specific_data['text'] markuptext += ' (%s)' % gobject.markup_escape_text(text) return markuptext - def _translate_mood(mood): + def _translate_mood(self, mood): if mood in MOODS: return MOODS[mood] else: @@ -446,20 +446,25 @@ SUPPORTED_PERSONAL_USER_EVENTS = [UserMoodPEP, UserTunePEP, UserActivityPEP, UserNicknamePEP] class ConnectionPEP(object): - + + def __init__(self, account, dispatcher, pubsub_connection): + self._account = account + self._dispatcher = dispatcher + self._pubsub_connection = pubsub_connection + def _pubsubEventCB(self, xmpp_dispatcher, msg): ''' Called when we receive with pubsub event. ''' if msg.getTag('error'): log.debug('PubsubEventCB received error stanza. Ignoring') - raise NodeProcessed + raise xmpp.NodeProcessed jid = helpers.get_full_jid_from_iq(msg) event_tag = msg.getTag('event') for pep_class in SUPPORTED_PERSONAL_USER_EVENTS: - pep = pep_class.get_tag_as_PEP(jid, self.name, event_tag) + pep = pep_class.get_tag_as_PEP(jid, self._account, event_tag) if pep: - self.dispatch('PEP_RECEIVED', (jid, pep.type)) + self._dispatcher.dispatch('PEP_RECEIVED', (jid, pep.type)) items = event_tag.getTag('items') if items: @@ -468,7 +473,8 @@ class ConnectionPEP(object): if entry: # for each entry in feed (there shouldn't be more than one, # but to be sure... - self.dispatch('ATOM_ENTRY', (atom.OldEntry(node=entry),)) + self._dispatcher.dispatch('ATOM_ENTRY', + (atom.OldEntry(node=entry),)) raise xmpp.NodeProcessed @@ -483,14 +489,14 @@ class ConnectionPEP(object): if message: i = item.addChild('text') i.addData(message) - self.send_pb_publish('', xmpp.NS_ACTIVITY, item, '0') + self._pubsub_connection.send_pb_publish('', xmpp.NS_ACTIVITY, item, '0') def retract_activity(self): if not self.pep_supported: return # not all server support retract, so send empty pep first self.send_activity(None) - self.send_pb_retract('', xmpp.NS_ACTIVITY, '0') + self._pubsub_connection.send_pb_retract('', xmpp.NS_ACTIVITY, '0') def send_mood(self, mood, message=None): if not self.pep_supported: @@ -501,13 +507,13 @@ class ConnectionPEP(object): if message: i = item.addChild('text') i.addData(message) - self.send_pb_publish('', xmpp.NS_MOOD, item, '0') + self._pubsub_connection.send_pb_publish('', xmpp.NS_MOOD, item, '0') def retract_mood(self): if not self.pep_supported: return self.send_mood(None) - self.send_pb_retract('', xmpp.NS_MOOD, '0') + self._pubsub_connection.send_pb_retract('', xmpp.NS_MOOD, '0') def send_tune(self, artist='', title='', source='', track=0, length=0, items=None): @@ -531,28 +537,27 @@ class ConnectionPEP(object): i.addData(length) if items: item.addChild(payload=items) - self.send_pb_publish('', xmpp.NS_TUNE, item, '0') + self._pubsub_connection.send_pb_publish('', xmpp.NS_TUNE, item, '0') def retract_tune(self): if not self.pep_supported: return # not all server support retract, so send empty pep first self.send_tune(None) - self.send_pb_retract('', xmpp.NS_TUNE, '0') + self._pubsub_connection.send_pb_retract('', xmpp.NS_TUNE, '0') def send_nickname(self, nick): if not self.pep_supported: return item = xmpp.Node('nick', {'xmlns': xmpp.NS_NICK}) item.addData(nick) - self.send_pb_publish('', xmpp.NS_NICK, item, '0') + self._pubsub_connection.send_pb_publish('', xmpp.NS_NICK, item, '0') def retract_nickname(self): if not self.pep_supported: return # not all server support retract, so send empty pep first self.send_nickname(None) - self.send_pb_retract('', xmpp.NS_NICK, '0') - + self._pubsub_connection.send_pb_retract('', xmpp.NS_NICK, '0') # vim: se ts=3: