comparison src/plugins/plugin_xep_0096.py @ 1409:3265a2639182

massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
author souliane <souliane@mailoo.org>
date Thu, 16 Apr 2015 14:57:57 +0200
parents 069ad98b360d
children 7b0fcefd52d4
comparison
equal deleted inserted replaced
1408:8a7145138330 1409:3265a2639182
94 file_el = file_elts[0] 94 file_el = file_elts[0]
95 filename = file_el["name"] 95 filename = file_el["name"]
96 file_size = file_el["size"] 96 file_size = file_el["size"]
97 file_date = file_el.getAttribute("date", "") 97 file_date = file_el.getAttribute("date", "")
98 file_hash = file_el.getAttribute("hash", "") 98 file_hash = file_el.getAttribute("hash", "")
99 log.info(_("File proposed: name=[%(name)s] size=%(size)s") % {'name': filename, 'size': file_size}) 99 log.info(_(u"File proposed: name=[%(name)s] size=%(size)s") % {'name': filename, 'size': file_size})
100 for file_child_el in file_el.elements(): 100 for file_child_el in file_el.elements():
101 if file_child_el.name == "desc": 101 if file_child_el.name == "desc":
102 file_desc = unicode(file_child_el) 102 file_desc = unicode(file_child_el)
103 elif file_child_el.name == "range": 103 elif file_child_el.name == "range":
104 can_range = True 104 can_range = True
178 range_elt['offset'] = str(range_offset) 178 range_elt['offset'] = str(range_offset)
179 #TODO: manage range length 179 #TODO: manage range length
180 misc_elts.append(range_elt) 180 misc_elts.append(range_elt)
181 self.host.plugins["XEP-0095"].acceptStream(data["id"], data['from'], feature_elt, misc_elts, profile) 181 self.host.plugins["XEP-0095"].acceptStream(data["id"], data['from'], feature_elt, misc_elts, profile)
182 else: 182 else:
183 log.debug(_("Transfer [%s] refused") % sid) 183 log.debug(_(u"Transfer [%s] refused") % sid)
184 self.host.plugins["XEP-0095"].sendRejectedError(data["id"], data['from'], profile=profile) 184 self.host.plugins["XEP-0095"].sendRejectedError(data["id"], data['from'], profile=profile)
185 del(client._xep_0096_waiting_for_approval[sid]) 185 del(client._xep_0096_waiting_for_approval[sid])
186 186
187 def _transferSucceeded(self, sid, file_obj, stream_method, profile): 187 def _transferSucceeded(self, sid, file_obj, stream_method, profile):
188 """Called by the stream method when transfer successfuly finished 188 """Called by the stream method when transfer successfuly finished
196 """Called when something went wrong with the transfer 196 """Called when something went wrong with the transfer
197 @param id: stream id 197 @param id: stream id
198 @param reason: can be TIMEOUT, IO_ERROR, PROTOCOL_ERROR""" 198 @param reason: can be TIMEOUT, IO_ERROR, PROTOCOL_ERROR"""
199 client = self.host.getClient(profile) 199 client = self.host.getClient(profile)
200 data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid] 200 data, timeout, stream_method, failed_methods = client._xep_0096_waiting_for_approval[sid]
201 log.warning(_('Transfer %(id)s failed with stream method %(s_method)s: %(reason)s') % { 201 log.warning(_(u'Transfer %(id)s failed with stream method %(s_method)s: %(reason)s') % {
202 'id': sid, 202 'id': sid,
203 's_method': stream_method, 203 's_method': stream_method,
204 'reason': reason}) 204 'reason': reason})
205 filepath = file_obj.name 205 filepath = file_obj.name
206 file_obj.close() 206 file_obj.close()
211 211
212 def fileCb(self, filepath, sid, size, profile, IQ): 212 def fileCb(self, filepath, sid, size, profile, IQ):
213 if IQ['type'] == "error": 213 if IQ['type'] == "error":
214 stanza_err = jabber.error.exceptionFromStanza(IQ) 214 stanza_err = jabber.error.exceptionFromStanza(IQ)
215 if stanza_err.code == '403' and stanza_err.condition == 'forbidden': 215 if stanza_err.code == '403' and stanza_err.condition == 'forbidden':
216 log.debug(_("File transfer refused by %s") % IQ['from']) 216 log.debug(_(u"File transfer refused by %s") % IQ['from'])
217 self.host.bridge.newAlert(_("The contact %s refused your file") % IQ['from'], _("File refused"), "INFO", profile) 217 self.host.bridge.newAlert(_("The contact %s refused your file") % IQ['from'], _("File refused"), "INFO", profile)
218 else: 218 else:
219 log.warning(_("Error during file transfer with %s") % IQ['from']) 219 log.warning(_(u"Error during file transfer with %s") % IQ['from'])
220 self.host.bridge.newAlert(_("Something went wrong during the file transfer session intialisation with %s") % IQ['from'], _("File transfer error"), "ERROR", profile) 220 self.host.bridge.newAlert(_("Something went wrong during the file transfer session intialisation with %s") % IQ['from'], _("File transfer error"), "ERROR", profile)
221 return 221 return
222 222
223 si_elt = IQ.firstChildElement() 223 si_elt = IQ.firstChildElement()
224 224
287 sid, offer = self.host.plugins["XEP-0095"].proposeStream(jid.JID(to_jid), PROFILE, feature_elt, file_transfer_elts, profile_key=profile) 287 sid, offer = self.host.plugins["XEP-0095"].proposeStream(jid.JID(to_jid), PROFILE, feature_elt, file_transfer_elts, profile_key=profile)
288 offer.addCallback(self.fileCb, filepath, sid, size, profile) 288 offer.addCallback(self.fileCb, filepath, sid, size, profile)
289 return sid 289 return sid
290 290
291 def sendSuccessCb(self, sid, file_obj, stream_method, profile): 291 def sendSuccessCb(self, sid, file_obj, stream_method, profile):
292 log.info(_('Transfer %(sid)s successfuly finished [%(profile)s]') 292 log.info(_(u'Transfer %(sid)s successfuly finished [%(profile)s]')
293 % {"sid": sid, "profile": profile}) 293 % {"sid": sid, "profile": profile})
294 file_obj.close() 294 file_obj.close()
295 295
296 def sendFailureCb(self, sid, file_obj, stream_method, reason, profile): 296 def sendFailureCb(self, sid, file_obj, stream_method, reason, profile):
297 file_obj.close() 297 file_obj.close()
298 log.warning(_('Transfer %(id)s failed with stream method %(s_method)s: %(reason)s [%(profile)s]') % {'id': sid, "s_method": stream_method, 'reason': reason, 'profile': profile}) 298 log.warning(_(u'Transfer %(id)s failed with stream method %(s_method)s: %(reason)s [%(profile)s]') % {'id': sid, "s_method": stream_method, 'reason': reason, 'profile': profile})