diff src/plugins/plugin_xep_0163.py @ 594:e629371a28d3

Fix pep8 support in src/plugins.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents beaf6bec2fcd
children 84a6e83157c2
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0163.py	Mon Jan 21 00:59:50 2013 +0100
+++ b/src/plugins/plugin_xep_0163.py	Fri Jan 18 17:55:35 2013 +0100
@@ -26,32 +26,33 @@
 import twisted.internet.error
 from twisted.words.xish import domish
 
-from wokkel import disco,pubsub
+from wokkel import disco, pubsub
 from wokkel.formats import Mood
 
 NS_USER_MOOD = 'http://jabber.org/protocol/mood'
 
 PLUGIN_INFO = {
-"name": "Personal Eventing Protocol Plugin",
-"import_name": "XEP-0163",
-"type": "XEP",
-"protocols": ["XEP-0163", "XEP-0107"],
-"dependencies": ["XEP-0060"],
-"main": "XEP_0163",
-"handler": "no",
-"description": _("""Implementation of Personal Eventing Protocol""")
+    "name": "Personal Eventing Protocol Plugin",
+    "import_name": "XEP-0163",
+    "type": "XEP",
+    "protocols": ["XEP-0163", "XEP-0107"],
+    "dependencies": ["XEP-0060"],
+    "main": "XEP_0163",
+    "handler": "no",
+    "description": _("""Implementation of Personal Eventing Protocol""")
 }
 
+
 class XEP_0163(object):
 
     def __init__(self, host):
         info(_("PEP plugin initialization"))
         self.host = host
-        self.pep_events=set()
-        self.pep_out_cb={}
+        self.pep_events = set()
+        self.pep_out_cb = {}
         host.trigger.add("PubSub Disco Info", self.disoInfoTrigger)
-        host.bridge.addSignal("personalEvent", ".plugin", signature='ssa{ss}s') #args: from (jid), type(MOOD, TUNE, etc), data, profile
-        host.bridge.addMethod("sendPersonalEvent", ".plugin", in_sign='sa{ss}s', out_sign='i', method=self.sendPersonalEvent) #args: type(MOOD, TUNE, etc), data, profile_key; return 0 or error_code
+        host.bridge.addSignal("personalEvent", ".plugin", signature='ssa{ss}s')  # args: from (jid), type(MOOD, TUNE, etc), data, profile
+        host.bridge.addMethod("sendPersonalEvent", ".plugin", in_sign='sa{ss}s', out_sign='i', method=self.sendPersonalEvent)  # args: type(MOOD, TUNE, etc), data, profile_key; return 0 or error_code
         self.addPEPEvent("MOOD", NS_USER_MOOD, self.userMoodCB, self.sendMood)
 
     def disoInfoTrigger(self, disco_info, profile):
@@ -62,7 +63,7 @@
         disco_info.extend(map(disco.DiscoFeature, self.pep_events))
         return True
 
-    def addPEPEvent(self, event_type, name, in_callback, out_callback = None, notify = True):
+    def addPEPEvent(self, event_type, name, in_callback, out_callback=None, notify=True):
         """Add a Personal Eventing Protocol event manager
         @param event_type: type of the event (always uppercase), can be MOOD, TUNE, etc
         @param name: namespace of the node (e.g. http://jabber.org/protocol/mood for User Mood)
@@ -73,7 +74,7 @@
             self.pep_out_cb[event_type] = out_callback
         self.pep_events.add(name)
         if notify:
-            self.pep_events.add(name+"+notify")
+            self.pep_events.add(name + "+notify")
         self.host.plugins["XEP-0060"].addManagedNode(name, in_callback)
 
     def sendPEPEvent(self, namespace, data, profile):
@@ -83,7 +84,7 @@
         @param profile: profile which send the data"""
 
         item = pubsub.Item(payload=data)
-        self.host.plugins["XEP-0060"].publish(None, namespace, [item], profile_key = profile)
+        self.host.plugins["XEP-0060"].publish(None, namespace, [item], profile_key=profile)
 
     def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'):
         """Send personal event after checking the data is alright
@@ -96,7 +97,7 @@
             error(_('Trying to send personal event with an unknown profile key [%s]') % profile_key)
             return 1
         if not event_type in self.pep_out_cb.keys():
-            error (_('Trying to send personal event for an unknown type'))
+            error(_('Trying to send personal event for an unknown type'))
             return 2
         return self.pep_out_cb[event_type](data, profile)
 
@@ -105,7 +106,7 @@
             debug(_("No item found"))
             return
         try:
-            mood_elem = filter(lambda x:x.name == "mood", itemsEvent.items[0].children)[0]
+            mood_elem = filter(lambda x: x.name == "mood", itemsEvent.items[0].children)[0]
         except KeyError:
             error(_("Can't find mood element in mood event"))
             return
@@ -113,7 +114,7 @@
         if not _mood:
             debug(_("No mood found"))
             return
-        self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood":_mood.value or "", "text":_mood.text or ""}, profile)
+        self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": _mood.value or "", "text": _mood.text or ""}, profile)
 
     def sendMood(self, data, profile):
         """Send XEP-0107's User Mood
@@ -121,7 +122,7 @@
         @param profile: profile which send the mood"""
         try:
             value = data['mood'].lower()
-            text = data['text'] if data.has_key('text') else ''
+            text = data['text'] if 'text' in data else ''
         except KeyError:
             error(_("Mood data must contain at least 'mood' key"))
             return 3
@@ -129,6 +130,7 @@
         self.sendPEPEvent(NS_USER_MOOD, _mood, profile)
         return 0
 
+
 class UserMood(Mood, domish.Element):
     """Improved wokkel Mood which is also a domish.Element"""
 
@@ -138,4 +140,3 @@
         self.addElement(value)
         if text:
             self.addElement('text', content=text)
-