XEP-0191: wrap functions with coroutine_wrapper

This commit is contained in:
mathieui 2015-02-23 19:33:22 +01:00
parent 6e35948276
commit 6e8235544c
No known key found for this signature in database
GPG key ID: C59F84CEEFD616E3

View file

@ -9,6 +9,7 @@
import logging
from slixmpp import Iq
from slixmpp import coroutine_wrapper
from slixmpp.plugins import BasePlugin
from slixmpp.xmlstream.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath
@ -45,14 +46,18 @@ class XEP_0191(BasePlugin):
self.xmpp.remove_handler('Blocked Contact')
self.xmpp.remove_handler('Unblocked Contact')
def get_blocked(self, ifrom=None, timeout=None, callback=None):
@coroutine_wrapper
def get_blocked(self, ifrom=None, timeout=None, callback=None,
coroutine=False):
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq['from'] = ifrom
iq.enable('blocklist')
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback, coroutine=coroutine)
def block(self, jids, ifrom=None, timeout=None, callback=None):
@coroutine_wrapper
def block(self, jids, ifrom=None, timeout=None, callback=None,
coroutine=False):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['from'] = ifrom
@ -61,9 +66,11 @@ class XEP_0191(BasePlugin):
jids = [jids]
iq['block']['items'] = jids
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback, coroutine=coroutine)
def unblock(self, jids=None, ifrom=None, timeout=None, callback=None):
@coroutine_wrapper
def unblock(self, jids=None, ifrom=None, timeout=None, callback=None,
coroutine=False):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['from'] = ifrom
@ -74,7 +81,7 @@ class XEP_0191(BasePlugin):
jids = [jids]
iq['unblock']['items'] = jids
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback, coroutine=coroutine)
def _handle_blocked(self, iq):
self.xmpp.event('blocked', iq)