comparison src/plugins/plugin_xep_0054.py @ 916:1a759096ccbd

core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
author Goffi <goffi@goffi.org>
date Fri, 21 Mar 2014 16:27:09 +0100
parents 1fe00f0c9a91
children 01342bfe9f41
comparison
equal deleted inserted replaced
915:6f96ee4d8cc0 916:1a759096ccbd
17 17
18 # You should have received a copy of the GNU Affero General Public License 18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21 from sat.core.i18n import _ 21 from sat.core.i18n import _
22 from sat.core.constants import Const as C
22 from logging import debug, info, error 23 from logging import debug, info, error
23 from twisted.internet import threads 24 from twisted.internet import threads
24 from twisted.internet.defer import inlineCallbacks, returnValue 25 from twisted.internet.defer import inlineCallbacks, returnValue
25 from twisted.words.protocols.jabber import jid 26 from twisted.words.protocols.jabber import jid
26 from twisted.words.protocols.jabber.xmlstream import IQ 27 from twisted.words.protocols.jabber.xmlstream import IQ
204 """Called when something is wrong with registration""" 205 """Called when something is wrong with registration"""
205 if failure.value.stanza.hasAttribute("from"): 206 if failure.value.stanza.hasAttribute("from"):
206 error(_("Can't find VCard of %s") % failure.value.stanza['from']) 207 error(_("Can't find VCard of %s") % failure.value.stanza['from'])
207 self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, profile) # FIXME: maybe an error message would be better 208 self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, profile) # FIXME: maybe an error message would be better
208 209
209 def getCard(self, target_s, profile_key='@DEFAULT@'): 210 def getCard(self, target_s, profile_key=C.PROF_KEY_NONE):
210 """Ask server for VCard 211 """Ask server for VCard
211 @param target_s: jid from which we want the VCard 212 @param target_s: jid from which we want the VCard
212 @result: id to retrieve the profile""" 213 @result: id to retrieve the profile"""
213 current_jid, xmlstream = self.host.getJidNStream(profile_key) 214 current_jid, xmlstream = self.host.getJidNStream(profile_key)
214 if not xmlstream: 215 if not xmlstream:
251 photo_elt.addElement('TYPE', content='image/png') 252 photo_elt.addElement('TYPE', content='image/png')
252 photo_elt.addElement('BINVAL', content=b64encode(img_buf.getvalue())) 253 photo_elt.addElement('BINVAL', content=b64encode(img_buf.getvalue()))
253 img_hash = sha1(img_buf.getvalue()).hexdigest() 254 img_hash = sha1(img_buf.getvalue()).hexdigest()
254 return (vcard_set, img_hash) 255 return (vcard_set, img_hash)
255 256
256 def setAvatar(self, filepath, profile_key='@DEFAULT@'): 257 def setAvatar(self, filepath, profile_key=C.PROF_KEY_NONE):
257 """Set avatar of the profile 258 """Set avatar of the profile
258 @param filepath: path of the image of the avatar""" 259 @param filepath: path of the image of the avatar"""
259 #TODO: This is a temporary way of setting avatar, as other VCard informations are not managed. 260 #TODO: This is a temporary way of setting avatar, as other VCard informations are not managed.
260 # A proper full VCard management should be done (and more generaly a public/private profile) 261 # A proper full VCard management should be done (and more generaly a public/private profile)
261 client = self.host.getClient(profile_key) 262 client = self.host.getClient(profile_key)