comparison src/plugins/plugin_xep_0249.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
comparison
equal deleted inserted replaced
593:70bae685d05c 594:e629371a28d3
32 try: 32 try:
33 from twisted.words.protocols.xmlstream import XMPPHandler 33 from twisted.words.protocols.xmlstream import XMPPHandler
34 except ImportError: 34 except ImportError:
35 from wokkel.subprotocols import XMPPHandler 35 from wokkel.subprotocols import XMPPHandler
36 36
37 MESSAGE= '/message' 37 MESSAGE = '/message'
38 NS_DIRECT_MUC_INVITATION = 'jabber:x:conference' 38 NS_DIRECT_MUC_INVITATION = 'jabber:x:conference'
39 DIRECT_MUC_INVITATION_REQUEST = MESSAGE + '/x[@xmlns="' + NS_DIRECT_MUC_INVITATION + '"]' 39 DIRECT_MUC_INVITATION_REQUEST = MESSAGE + '/x[@xmlns="' + NS_DIRECT_MUC_INVITATION + '"]'
40 40
41 PLUGIN_INFO = { 41 PLUGIN_INFO = {
42 "name": "XEP 0249 Plugin", 42 "name": "XEP 0249 Plugin",
43 "import_name": "XEP-0249", 43 "import_name": "XEP-0249",
44 "type": "XEP", 44 "type": "XEP",
45 "protocols": ["XEP-0249"], 45 "protocols": ["XEP-0249"],
46 "dependencies": ["XEP-0045"], 46 "dependencies": ["XEP-0045"],
47 "main": "XEP_0249", 47 "main": "XEP_0249",
48 "handler": "yes", 48 "handler": "yes",
49 "description": _("""Implementation of Direct MUC Invitations""") 49 "description": _("""Implementation of Direct MUC Invitations""")
50 } 50 }
51
51 52
52 class XEP_0249(object): 53 class XEP_0249(object):
53 54
54 def __init__(self, host): 55 def __init__(self, host):
55 info(_("Plugin XEP_0249 initialization")) 56 info(_("Plugin XEP_0249 initialization"))
69 """ 70 """
70 profile = self.host.memory.getProfileName(profile_key) 71 profile = self.host.memory.getProfileName(profile_key)
71 if not profile: 72 if not profile:
72 error(_("Profile doesn't exists !")) 73 error(_("Profile doesn't exists !"))
73 return 74 return
74 message = domish.Element((None,'message')) 75 message = domish.Element((None, 'message'))
75 message["to"] = target.full() 76 message["to"] = target.full()
76 x_elt = message.addElement('x',NS_DIRECT_MUC_INVITATION) 77 x_elt = message.addElement('x', NS_DIRECT_MUC_INVITATION)
77 x_elt['jid'] = room.userhost() 78 x_elt['jid'] = room.userhost()
78 for opt in options: 79 for opt in options:
79 x_elt[opt] = options[opt] 80 x_elt[opt] = options[opt]
80 self.host.profiles[profile].xmlstream.send(message) 81 self.host.profiles[profile].xmlstream.send(message)
81 82
82 def _invite(self, target, service, roomId, options = {}, profile_key='@DEFAULT@'): 83 def _invite(self, target, service, roomId, options={}, profile_key='@DEFAULT@'):
83 """ 84 """
84 Invite an user to a room 85 Invite an user to a room
85 @param target: jid of the user to invite 86 @param target: jid of the user to invite
86 @param service: jid of the MUC service 87 @param service: jid of the MUC service
87 @param roomId: name of the room 88 @param roomId: name of the room
88 @param profile_key: %(doc_profile_key)s 89 @param profile_key: %(doc_profile_key)s
89 """ 90 """
90 #TODO: check parameters validity 91 #TODO: check parameters validity
91 self.invite(jid.JID(target), jid.JID("%s@%s" % (roomId, service)), options, profile_key) 92 self.invite(jid.JID(target), jid.JID("%s@%s" % (roomId, service)), options, profile_key)
92 93
93
94 def onInvitation(self, message, profile): 94 def onInvitation(self, message, profile):
95 """ 95 """
96 called when an invitation is received 96 called when an invitation is received
97 @param message: message element 97 @param message: message element
98 @profile: %(doc_profile)s 98 @profile: %(doc_profile)s
99 """ 99 """
100 info(_('Invitation received for room %(room)s [%(profile)s]') % {'room':'','profile':profile}) 100 info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': '', 'profile': profile})
101 try: 101 try:
102 room = jid.JID(message.firstChildElement()['jid']) 102 room = jid.JID(message.firstChildElement()['jid'])
103 except: 103 except:
104 error(_('Error while parsing invitation')) 104 error(_('Error while parsing invitation'))
105 return 105 return
114 def __init__(self, plugin_parent): 114 def __init__(self, plugin_parent):
115 self.plugin_parent = plugin_parent 115 self.plugin_parent = plugin_parent
116 self.host = plugin_parent.host 116 self.host = plugin_parent.host
117 117
118 def connectionInitialized(self): 118 def connectionInitialized(self):
119 self.xmlstream.addObserver(DIRECT_MUC_INVITATION_REQUEST, self.plugin_parent.onInvitation, profile = self.parent.profile) 119 self.xmlstream.addObserver(DIRECT_MUC_INVITATION_REQUEST, self.plugin_parent.onInvitation, profile=self.parent.profile)
120 120
121 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 121 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
122 return [disco.DiscoFeature(NS_DIRECT_MUC_INVITATION)] 122 return [disco.DiscoFeature(NS_DIRECT_MUC_INVITATION)]
123 123
124 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 124 def getDiscoItems(self, requestor, target, nodeIdentifier=''):