# HG changeset patch # User Goffi # Date 1345123036 -7200 # Node ID ee95ff721b68ad112510b8c733f706c159559349 # Parent 23cbdf0a07774855bebffa10c4ca693e45d17c83 plugin xep-0054: changed deprecated deferredGenerator for inlineCallbacks diff -r 23cbdf0a0777 -r ee95ff721b68 src/plugins/plugin_xep_0054.py --- a/src/plugins/plugin_xep_0054.py Wed Aug 15 15:50:46 2012 +0200 +++ b/src/plugins/plugin_xep_0054.py Thu Aug 16 15:17:16 2012 +0200 @@ -22,6 +22,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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