XEP-0191: wrap functions with coroutine_wrapper
This commit is contained in:
parent
6e35948276
commit
6e8235544c
1 changed files with 13 additions and 6 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue