plugin xep-0054: changed deprecated deferredGenerator for inlineCallbacks
This commit is contained in:
parent
8f622601c6
commit
f6cdc6383d
1 changed files with 6 additions and 8 deletions
|
|
@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
from logging import debug, info, error
|
||||
from twisted.words.xish import domish
|
||||
from twisted.internet import protocol, defer, threads, reactor
|
||||
from twisted.internet.defer import inlineCallbacks, returnValue
|
||||
from twisted.words.protocols.jabber import client, jid, xmlstream
|
||||
from twisted.words.protocols.jabber import error as jab_error
|
||||
from twisted.words.protocols.jabber.xmlstream import IQ
|
||||
|
|
@ -128,7 +129,7 @@ class XEP_0054():
|
|||
debug(_("file [%s] already in cache") % hash)
|
||||
return hash
|
||||
|
||||
@defer.deferredGenerator
|
||||
@inlineCallbacks
|
||||
def vCard2Dict(self, vcard, target, profile):
|
||||
"""Convert a VCard to a dict, and save binaries"""
|
||||
debug (_("parsing vcard"))
|
||||
|
|
@ -148,10 +149,7 @@ class XEP_0054():
|
|||
elif elem.name == 'BDAY':
|
||||
dictionary['birthday'] = unicode(elem)
|
||||
elif elem.name == 'PHOTO':
|
||||
d2 = defer.waitForDeferred(
|
||||
threads.deferToThread(self.save_photo, elem))
|
||||
yield d2
|
||||
dictionary["avatar"] = d2.getResult()
|
||||
dictionary["avatar"] = yield threads.deferToThread(self.save_photo, elem)
|
||||
if not dictionary["avatar"]: #can happen in case of e.g. empty photo elem
|
||||
del dictionary['avatar']
|
||||
else:
|
||||
|
|
@ -159,7 +157,7 @@ class XEP_0054():
|
|||
else:
|
||||
info (_('FIXME: [%s] VCard tag is not managed yet') % elem.name)
|
||||
|
||||
yield dictionary
|
||||
returnValue(dictionary)
|
||||
|
||||
def vcard_ok(self, answer, profile):
|
||||
"""Called after the first get IQ"""
|
||||
|
|
@ -170,12 +168,12 @@ class XEP_0054():
|
|||
d.addCallback(lambda data: self.host.bridge.actionResult("RESULT", answer['id'], data))
|
||||
else:
|
||||
error (_("FIXME: vCard not found as first child element"))
|
||||
self.host.bridge.actionResult("SUPPRESS", answer['id'], {}) #FIXME: maybe an error message would be best
|
||||
self.host.bridge.actionResult("SUPPRESS", answer['id'], {}) #FIXME: maybe an error message would be better
|
||||
|
||||
def vcard_err(self, failure):
|
||||
"""Called when something is wrong with registration"""
|
||||
error (_("Can't find VCard of %s") % failure.value.stanza['from'])
|
||||
self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}) #FIXME: maybe an error message would be best
|
||||
self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}) #FIXME: maybe an error message would be better
|
||||
|
||||
def getCard(self, target, profile_key='@DEFAULT@'):
|
||||
"""Ask server for VCard
|
||||
|
|
|
|||
Loading…
Reference in a new issue