Fix pep8 support in src/plugins.
This commit is contained in:
parent
e51a8a650b
commit
0dca274360
1 changed files with 1052 additions and 1079 deletions
|
|
@ -26,32 +26,33 @@ from twisted.words.protocols.jabber import error as jab_error
|
|||
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 @@ class XEP_0163(object):
|
|||
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 @@ class XEP_0163(object):
|
|||
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 @@ class XEP_0163(object):
|
|||
@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 @@ class XEP_0163(object):
|
|||
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 @@ class XEP_0163(object):
|
|||
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 @@ class XEP_0163(object):
|
|||
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 @@ class XEP_0163(object):
|
|||
@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 @@ class XEP_0163(object):
|
|||
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 @@ class UserMood(Mood, domish.Element):
|
|||
self.addElement(value)
|
||||
if text:
|
||||
self.addElement('text', content=text)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue