comparison src/plugins/plugin_xep_0050.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents e1842ebcb2f3
children eef1f200d733
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _, D_ 20 from sat.core.i18n import _, D_
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from logging import debug, info, warning, error 22 from sat.core.log import getLogger
23 log = getLogger(__name__)
23 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
24 from twisted.words.protocols.jabber import error as xmpp_error 25 from twisted.words.protocols import jabber
25 from twisted.words.xish import domish 26 from twisted.words.xish import domish
26 from twisted.internet import defer 27 from twisted.internet import defer
27 from wokkel import disco, iwokkel, data_form, compat 28 from wokkel import disco, iwokkel, data_form, compat
28 from sat.core import exceptions 29 from sat.core import exceptions
29 from sat.memory.memory import Sessions 30 from sat.memory.memory import Sessions
104 allowed = set(self.allowed_jids) 105 allowed = set(self.allowed_jids)
105 for group in self.allowed_groups: 106 for group in self.allowed_groups:
106 try: 107 try:
107 allowed.update(self.client.roster.getJidsFromGroup(group)) 108 allowed.update(self.client.roster.getJidsFromGroup(group))
108 except exceptions.UnknownGroupError: 109 except exceptions.UnknownGroupError:
109 warning(_("The groups [%(group)s] is unknown for profile [%(profile)s])" % {'group':group, 'profile':self.client.profile})) 110 log.warning(_("The groups [%(group)s] is unknown for profile [%(profile)s])" % {'group':group, 'profile':self.client.profile}))
110 if requestor.userhostJID() in allowed: 111 if requestor.userhostJID() in allowed:
111 return True 112 return True
112 return False 113 return False
113 114
114 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 115 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
167 """ Send error stanza 168 """ Send error stanza
168 @param error_constant: one of XEP_OO50.ERROR 169 @param error_constant: one of XEP_OO50.ERROR
169 @param request: original request (domish.Element) 170 @param request: original request (domish.Element)
170 """ 171 """
171 xmpp_condition, cmd_condition = error_constant 172 xmpp_condition, cmd_condition = error_constant
172 iq_elt = xmpp_error.StanzaError(xmpp_condition).toResponse(request) 173 iq_elt = jabber.error.StanzaError(xmpp_condition).toResponse(request)
173 if cmd_condition: 174 if cmd_condition:
174 error_elt = iq_elt.elements(None, "error").next() 175 error_elt = iq_elt.elements(None, "error").next()
175 error_elt.addElement(cmd_condition, NS_COMMANDS) 176 error_elt.addElement(cmd_condition, NS_COMMANDS)
176 self.client.xmlstream.send(iq_elt) 177 self.client.xmlstream.send(iq_elt)
177 del self.sessions[session_id] 178 del self.sessions[session_id]
206 ('bad-request', 'bad-action'), ('bad-request', 'bad-locale'), ('bad-request','bad-payload'), 207 ('bad-request', 'bad-action'), ('bad-request', 'bad-locale'), ('bad-request','bad-payload'),
207 ('bad-request','bad-sessionid'), ('not-allowed','session-expired'), ('forbidden', None), 208 ('bad-request','bad-sessionid'), ('not-allowed','session-expired'), ('forbidden', None),
208 ('item-not-found', None), ('feature-not-implemented', None), ('internal-server-error', None)) # XEP-0050 §4.4 Table 5 209 ('item-not-found', None), ('feature-not-implemented', None), ('internal-server-error', None)) # XEP-0050 §4.4 Table 5
209 210
210 def __init__(self, host): 211 def __init__(self, host):
211 info(_("plugin XEP-0050 initialization")) 212 log.info(_("plugin XEP-0050 initialization"))
212 self.host = host 213 self.host = host
213 self.requesting = Sessions() 214 self.requesting = Sessions()
214 self.answering = {} 215 self.answering = {}
215 host.bridge.addMethod("requestCommand", ".plugin", in_sign='ss', out_sign='s', 216 host.bridge.addMethod("requestCommand", ".plugin", in_sign='ss', out_sign='s',
216 method=self._requestCommandsList, 217 method=self._requestCommandsList,
288 else: 289 else:
289 # we have started a several forms sessions 290 # we have started a several forms sessions
290 try: 291 try:
291 session_data = self.requesting.profileGet(data["session_id"], profile) 292 session_data = self.requesting.profileGet(data["session_id"], profile)
292 except KeyError: 293 except KeyError:
293 warning ("session id doesn't exist, session has probably expired") 294 log.warning ("session id doesn't exist, session has probably expired")
294 # TODO: send error dialog 295 # TODO: send error dialog
295 return defer.succeed({}) 296 return defer.succeed({})
296 session_id = data["session_id"] 297 session_id = data["session_id"]
297 entity = session_data['jid'] 298 entity = session_data['jid']
298 try: 299 try: