From f6cdc6383d84bfaa6ec98f98beb7ef43e8abf768 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 16 Aug 2012 15:17:16 +0200 Subject: [PATCH] plugin xep-0054: changed deprecated deferredGenerator for inlineCallbacks --- src/plugins/plugin_xep_0054.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/plugins/plugin_xep_0054.py b/src/plugins/plugin_xep_0054.py index dc1d2be0..c138eb1e 100755 --- a/src/plugins/plugin_xep_0054.py +++ b/src/plugins/plugin_xep_0054.py @@ -22,6 +22,7 @@ along with this program. If not, see . 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