comparison src/plugins/plugin_xep_0054.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 a568fc14ab46
comparison
equal deleted inserted replaced
1408:8a7145138330 1409:3265a2639182
169 """ 169 """
170 filename = self._getFilename(hash_) 170 filename = self._getFilename(hash_)
171 if not os.path.exists(filename): 171 if not os.path.exists(filename):
172 with open(filename, 'wb') as file_: 172 with open(filename, 'wb') as file_:
173 file_.write(data) 173 file_.write(data)
174 log.debug(_("file saved to %s") % hash_) 174 log.debug(_(u"file saved to %s") % hash_)
175 else: 175 else:
176 log.debug(_("file [%s] already in cache") % hash_) 176 log.debug(_(u"file [%s] already in cache") % hash_)
177 177
178 def savePhoto(self, photo_xml): 178 def savePhoto(self, photo_xml):
179 """Parse a <PHOTO> elem and save the picture""" 179 """Parse a <PHOTO> elem and save the picture"""
180 for elem in photo_xml.elements(): 180 for elem in photo_xml.elements():
181 if elem.name == 'TYPE': 181 if elem.name == 'TYPE':
182 log.debug(_('Photo of type [%s] found') % str(elem)) 182 log.debug(_(u'Photo of type [%s] found') % str(elem))
183 if elem.name == 'BINVAL': 183 if elem.name == 'BINVAL':
184 log.debug(_('Decoding binary')) 184 log.debug(_('Decoding binary'))
185 decoded = b64decode(str(elem)) 185 decoded = b64decode(str(elem))
186 image_hash = sha1(decoded).hexdigest() 186 image_hash = sha1(decoded).hexdigest()
187 self.saveAvatarFile(decoded, image_hash) 187 self.saveAvatarFile(decoded, image_hash)
240 self.host.bridge.actionResult("SUPPRESS", answer['id'], {}, profile) # FIXME: maybe an error message would be better 240 self.host.bridge.actionResult("SUPPRESS", answer['id'], {}, profile) # FIXME: maybe an error message would be better
241 241
242 def _VCardEb(self, failure, profile): 242 def _VCardEb(self, failure, profile):
243 """Called when something is wrong with registration""" 243 """Called when something is wrong with registration"""
244 try: 244 try:
245 log.warning(_("Can't find VCard of %s") % failure.value.stanza['from']) 245 log.warning(_(u"Can't find VCard of %s") % failure.value.stanza['from'])
246 self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, profile) # FIXME: maybe an error message would be better 246 self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, profile) # FIXME: maybe an error message would be better
247 self.updateCache(jid.JID(failure.value.stanza['from']), "avatar", '', profile) 247 self.updateCache(jid.JID(failure.value.stanza['from']), "avatar", '', profile)
248 except AttributeError: # 'ConnectionLost' object has no attribute 'stanza' 248 except AttributeError: # 'ConnectionLost' object has no attribute 'stanza'
249 log.warning(_("Can't find VCard: %s") % failure.getErrorMessage()) 249 log.warning(_(u"Can't find VCard: %s") % failure.getErrorMessage())
250 250
251 def _getCard(self, target_s, profile_key=C.PROF_KEY_NONE): 251 def _getCard(self, target_s, profile_key=C.PROF_KEY_NONE):
252 return self.getCard(jid.JID(target_s), profile_key) 252 return self.getCard(jid.JID(target_s), profile_key)
253 253
254 def getCard(self, target, profile_key=C.PROF_KEY_NONE): 254 def getCard(self, target, profile_key=C.PROF_KEY_NONE):
260 current_jid, xmlstream = self.host.getJidNStream(profile_key) 260 current_jid, xmlstream = self.host.getJidNStream(profile_key)
261 if not xmlstream: 261 if not xmlstream:
262 raise exceptions.ProfileUnknownError('Asking vcard for a non-existant or not connected profile ({})'.format(profile_key)) 262 raise exceptions.ProfileUnknownError('Asking vcard for a non-existant or not connected profile ({})'.format(profile_key))
263 profile = self.host.memory.getProfileName(profile_key) 263 profile = self.host.memory.getProfileName(profile_key)
264 to_jid = target.userhostJID() 264 to_jid = target.userhostJID()
265 log.debug(_("Asking for %s's VCard") % to_jid.userhost()) 265 log.debug(_(u"Asking for %s's VCard") % to_jid.userhost())
266 reg_request = IQ(xmlstream, 'get') 266 reg_request = IQ(xmlstream, 'get')
267 reg_request["from"] = current_jid.full() 267 reg_request["from"] = current_jid.full()
268 reg_request["to"] = to_jid.userhost() 268 reg_request["to"] = to_jid.userhost()
269 reg_request.addElement('vCard', NS_VCARD) 269 reg_request.addElement('vCard', NS_VCARD)
270 reg_request.send(to_jid.userhost()).addCallbacks(self._VCardCb, self._VCardEb, callbackArgs=[profile], errbackArgs=[profile]) 270 reg_request.send(to_jid.userhost()).addCallbacks(self._VCardCb, self._VCardEb, callbackArgs=[profile], errbackArgs=[profile])
275 @param hash: SHA1 hash 275 @param hash: SHA1 hash
276 @return full_path 276 @return full_path
277 """ 277 """
278 filename = self.avatar_path + '/' + avatar_hash 278 filename = self.avatar_path + '/' + avatar_hash
279 if not os.path.exists(filename): 279 if not os.path.exists(filename):
280 log.error(_("Asking for an uncached avatar [%s]") % avatar_hash) 280 log.error(_(u"Asking for an uncached avatar [%s]") % avatar_hash)
281 return "" 281 return ""
282 return filename 282 return filename
283 283
284 def _buildSetAvatar(self, vcard_set, filepath): 284 def _buildSetAvatar(self, vcard_set, filepath):
285 try: 285 try: