changeset 485:ee95ff721b68

plugin xep-0054: changed deprecated deferredGenerator for inlineCallbacks
author Goffi <goffi@goffi.org>
date Thu, 16 Aug 2012 15:17:16 +0200
parents 23cbdf0a0777
children 0d9908ac775e
files src/plugins/plugin_xep_0054.py
diffstat 1 files changed, 6 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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