comparison src/plugins/plugin_xep_0055.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 40ad5a344332
children 16484ebb695b
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
16 16
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 logging import debug, info, warning, error 21 from sat.core.log import getLogger
22 log = getLogger(__name__)
22 from twisted.words.protocols.jabber.xmlstream import IQ 23 from twisted.words.protocols.jabber.xmlstream import IQ
23 from twisted.words.protocols.jabber import jid 24 from twisted.words.protocols.jabber import jid
25 from twisted.internet import defer
24 from wokkel import data_form 26 from wokkel import data_form
25 from sat.core.exceptions import DataError 27 from sat.core.exceptions import DataError
26 from sat.memory.memory import Sessions 28 from sat.memory.memory import Sessions
27 from sat.tools import xml_tools 29 from sat.tools import xml_tools
28 30
40 42
41 43
42 class XEP_0055(object): 44 class XEP_0055(object):
43 45
44 def __init__(self, host): 46 def __init__(self, host):
45 info(_("Jabber search plugin initialization")) 47 log.info(_("Jabber search plugin initialization"))
46 self.host = host 48 self.host = host
47 host.bridge.addMethod("getSearchUI", ".plugin", in_sign='ss', out_sign='s', 49 host.bridge.addMethod("getSearchUI", ".plugin", in_sign='ss', out_sign='s',
48 method=self._getSearchUI, 50 method=self._getSearchUI,
49 async=True) 51 async=True)
50 host.bridge.addMethod("searchRequest", ".plugin", in_sign='sa{ss}s', out_sign='s', 52 host.bridge.addMethod("searchRequest", ".plugin", in_sign='sa{ss}s', out_sign='s',
103 def _fieldsOk(self, answer, profile): 105 def _fieldsOk(self, answer, profile):
104 """got fields available""" 106 """got fields available"""
105 try: 107 try:
106 query_elts = answer.elements('jabber:iq:search', 'query').next() 108 query_elts = answer.elements('jabber:iq:search', 'query').next()
107 except StopIteration: 109 except StopIteration:
108 info(_("No query element found")) 110 log.info(_("No query element found"))
109 raise DataError # FIXME: StanzaError is probably more appropriate, check the RFC 111 raise DataError # FIXME: StanzaError is probably more appropriate, check the RFC
110 try: 112 try:
111 form_elt = query_elts.elements(data_form.NS_X_DATA, 'x').next() 113 form_elt = query_elts.elements(data_form.NS_X_DATA, 'x').next()
112 except StopIteration: 114 except StopIteration:
113 info(_("No data form found")) 115 log.info(_("No data form found"))
114 raise NotImplementedError("Only search through data form is implemented so far") 116 raise NotImplementedError("Only search through data form is implemented so far")
115 parsed_form = data_form.Form.fromElement(form_elt) 117 parsed_form = data_form.Form.fromElement(form_elt)
116 return xml_tools.dataForm2XMLUI(parsed_form, "") 118 return xml_tools.dataForm2XMLUI(parsed_form, "")
117 119
118 def _fieldsErr(self, failure, profile): 120 def _fieldsErr(self, failure, profile):
119 """ Called when something is wrong with fields request """ 121 """ Called when something is wrong with fields request """
120 info(_("Fields request failure: %s") % str(failure.value)) 122 log.info(_("Fields request failure: %s") % str(failure.value))
121 return failure 123 return failure
122 124
123 def _xmluiSearchRequest(self, raw_data, profile): 125 def _xmluiSearchRequest(self, raw_data, profile):
124 try: 126 try:
125 session_data = self._sessions.profileGet(raw_data["session_id"], profile) 127 session_data = self._sessions.profileGet(raw_data["session_id"], profile)
126 except KeyError: 128 except KeyError:
127 warning ("session id doesn't exist, session has probably expired") 129 log.warning ("session id doesn't exist, session has probably expired")
128 # TODO: send error dialog 130 # TODO: send error dialog
129 return defer.succeed({}) 131 return defer.succeed({})
130 132
131 data = xml_tools.XMLUIResult2DataFormResult(raw_data) 133 data = xml_tools.XMLUIResult2DataFormResult(raw_data)
132 entity =session_data['jid'] 134 entity =session_data['jid']
161 def _searchOk(self, answer, profile): 163 def _searchOk(self, answer, profile):
162 """got search available""" 164 """got search available"""
163 try: 165 try:
164 query_elts = answer.elements('jabber:iq:search', 'query').next() 166 query_elts = answer.elements('jabber:iq:search', 'query').next()
165 except StopIteration: 167 except StopIteration:
166 info(_("No query element found")) 168 log.info(_("No query element found"))
167 raise DataError # FIXME: StanzaError is probably more appropriate, check the RFC 169 raise DataError # FIXME: StanzaError is probably more appropriate, check the RFC
168 try: 170 try:
169 form_elt = query_elts.elements(data_form.NS_X_DATA, 'x').next() 171 form_elt = query_elts.elements(data_form.NS_X_DATA, 'x').next()
170 except StopIteration: 172 except StopIteration:
171 info(_("No data form found")) 173 log.info(_("No data form found"))
172 raise NotImplementedError("Only search through data form is implemented so far") 174 raise NotImplementedError("Only search through data form is implemented so far")
173 return xml_tools.dataFormResult2XMLUI(form_elt) 175 return xml_tools.dataFormResult2XMLUI(form_elt)
174 176
175 def _searchErr(self, failure, profile): 177 def _searchErr(self, failure, profile):
176 """ Called when something is wrong with search request """ 178 """ Called when something is wrong with search request """
177 info(_("Search request failure: %s") % str(failure.value)) 179 log.info(_("Search request failure: %s") % str(failure.value))
178 return failure 180 return failure