Add timeout_callback to a bunch of plugins as a parameter

This commit is contained in:
mathieui 2015-09-04 01:05:56 +02:00
parent 804b23d390
commit 00a0698720
No known key found for this signature in database
GPG Key ID: C59F84CEEFD616E3
10 changed files with 80 additions and 48 deletions

View File

@ -62,7 +62,7 @@ class XEP_0054(BasePlugin):
@future_wrapper
def get_vcard(self, jid=None, ifrom=None, local=None, cached=False,
callback=None, timeout=None):
callback=None, timeout=None, timeout_callback=None):
if local is None:
if jid is not None and not isinstance(jid, JID):
jid = JID(jid)
@ -101,11 +101,12 @@ class XEP_0054(BasePlugin):
iq['type'] = 'get'
iq.enable('vcard_temp')
return iq.send(callback=callback, timeout=timeout)
return iq.send(callback=callback, timeout=timeout,
timeout_callback=timeout_callback)
@future_wrapper
def publish_vcard(self, vcard=None, jid=None, ifrom=None,
callback=None, timeout=None):
callback=None, timeout=None, timeout_callback=None):
self.api['set_vcard'](jid, None, ifrom, vcard)
if self.xmpp.is_component:
return
@ -115,7 +116,8 @@ class XEP_0054(BasePlugin):
iq['from'] = ifrom
iq['type'] = 'set'
iq.append(vcard)
return iq.send(callback=callback, timeout=timeout)
return iq.send(callback=callback, timeout=timeout,
timeout_callback=timeout_callback)
def _handle_get_vcard(self, iq):
if iq['type'] == 'result':

View File

@ -86,7 +86,8 @@ class XEP_0080(BasePlugin):
ifrom = kwargs.get('ifrom', None)
callback = kwargs.get('callback', None)
timeout = kwargs.get('timeout', None)
for param in ('ifrom', 'block', 'callback', 'timeout', 'options'):
timeout_callback = kwargs.get('timeout_callback', None)
for param in ('ifrom', 'block', 'callback', 'timeout', 'options', 'timeout_callback'):
if param in kwargs:
del kwargs[param]
@ -97,9 +98,10 @@ class XEP_0080(BasePlugin):
options=options,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)
def stop(self, ifrom=None, callback=None, timeout=None):
def stop(self, ifrom=None, callback=None, timeout=None, timeout_callback=None):
"""
Clear existing user location information to stop notifications.
@ -115,4 +117,5 @@ class XEP_0080(BasePlugin):
return self.xmpp['xep_0163'].publish(geoloc,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=None)

View File

@ -45,25 +45,28 @@ class XEP_0084(BasePlugin):
return hashlib.sha1(data).hexdigest()
def retrieve_avatar(self, jid, id, url=None, ifrom=None,
callback=None, timeout=None):
callback=None, timeout=None, timeout_callback=None):
return self.xmpp['xep_0060'].get_item(jid, Data.namespace, id,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)
def publish_avatar(self, data, ifrom=None, callback=None,
timeout=None):
timeout=None, timeout_callback=None):
payload = Data()
payload['value'] = data
return self.xmpp['xep_0163'].publish(payload,
id=self.generate_id(data),
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)
def publish_avatar_metadata(self, items=None, pointers=None,
ifrom=None,
callback=None, timeout=None):
callback=None, timeout=None,
timeout_callback=None):
metadata = MetaData()
if items is None:
items = []
@ -83,9 +86,10 @@ class XEP_0084(BasePlugin):
id=info['id'],
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)
def stop(self, ifrom=None, callback=None, timeout=None):
def stop(self, ifrom=None, callback=None, timeout=None, timeout_callback=None):
"""
Clear existing avatar metadata information to stop notifications.
@ -102,4 +106,5 @@ class XEP_0084(BasePlugin):
node=MetaData.namespace,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)

View File

@ -70,7 +70,8 @@ class XEP_0092(BasePlugin):
iq['software_version']['os'] = self.os
iq.send()
def get_version(self, jid, ifrom=None, timeout=None, callback=None):
def get_version(self, jid, ifrom=None, timeout=None, callback=None,
timeout_callback=None):
"""
Retrieve the software version of a remote agent.
@ -82,4 +83,5 @@ class XEP_0092(BasePlugin):
iq['from'] = ifrom
iq['type'] = 'get'
iq['query'] = Version.namespace
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)

View File

@ -35,7 +35,7 @@ class XEP_0118(BasePlugin):
def publish_tune(self, artist=None, length=None, rating=None, source=None,
title=None, track=None, uri=None, options=None,
ifrom=None, callback=None, timeout=None):
ifrom=None, callback=None, timeout=None, timeout_callback=None):
"""
Publish the user's current tune.
@ -68,9 +68,10 @@ class XEP_0118(BasePlugin):
options=options,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)
def stop(self, ifrom=None, callback=None, timeout=None):
def stop(self, ifrom=None, callback=None, timeout=None, timeout_callback=None):
"""
Clear existing user tune information to stop notifications.
@ -87,4 +88,5 @@ class XEP_0118(BasePlugin):
node=UserTune.namespace,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)

View File

@ -33,8 +33,9 @@ class XEP_0152(BasePlugin):
def session_bind(self, jid):
self.xmpp['xep_0163'].register_pep('reachability', Reachability)
def publish_reachability(self, addresses, options=None,
ifrom=None, callback=None, timeout=None):
def publish_reachability(self, addresses, options=None, ifrom=None,
callback=None, timeout=None,
timeout_callback=None):
"""
Publish alternative addresses where the user can be reached.
@ -65,9 +66,10 @@ class XEP_0152(BasePlugin):
options=options,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)
def stop(self, ifrom=None, callback=None, timeout=None):
def stop(self, ifrom=None, callback=None, timeout=None, timeout_callback=None):
"""
Clear existing user activity information to stop notifications.
@ -84,4 +86,5 @@ class XEP_0152(BasePlugin):
node=Reachability.namespace,
ifrom=ifrom,
callback=callback,
timeout=timeout)
timeout=timeout,
timeout_callback=timeout_callback)

View File

@ -59,7 +59,7 @@ class XEP_0153(BasePlugin):
@future_wrapper
def set_avatar(self, jid=None, avatar=None, mtype=None, timeout=None,
callback=None):
callback=None, timeout_callback=None):
if jid is None:
jid = self.xmpp.boundjid.bare
@ -79,7 +79,8 @@ class XEP_0153(BasePlugin):
new_future = self.xmpp['xep_0054'].publish_vcard(jid=jid,
vcard=vcard,
timeout=timeout,
callback=next_callback)
callback=next_callback,
timeout_callback=timeout_callback)
new_future.add_done_callback(propagate_timeout_exception)
def next_callback(result):
@ -92,7 +93,8 @@ class XEP_0153(BasePlugin):
future.set_result(result)
first_future = self.xmpp['xep_0054'].get_vcard(jid, cached=False, timeout=timeout,
callback=custom_callback)
callback=custom_callback,
timeout_callback=timeout_callback)
first_future.add_done_callback(propagate_timeout_exception)
return future

View File

@ -45,14 +45,17 @@ 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):
def get_blocked(self, ifrom=None, timeout=None, callback=None,
timeout_callback=None):
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,
timeout_callback=timeout_callback)
def block(self, jids, ifrom=None, timeout=None, callback=None):
def block(self, jids, ifrom=None, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['from'] = ifrom
@ -61,9 +64,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,
timeout_callback=timeout_callback)
def unblock(self, jids=None, ifrom=None, timeout=None, callback=None):
def unblock(self, jids=None, ifrom=None, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['from'] = ifrom
@ -74,7 +79,8 @@ class XEP_0191(BasePlugin):
jids = [jids]
iq['unblock']['items'] = jids
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def _handle_blocked(self, iq):
self.xmpp.event('blocked', iq)

View File

@ -31,35 +31,40 @@ class XEP_0257(BasePlugin):
register_stanza_plugin(Iq, DisableCert)
register_stanza_plugin(Iq, RevokeCert)
def get_certs(self, ifrom=None, timeout=None, callback=None):
def get_certs(self, ifrom=None, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq['from'] = ifrom
iq.enable('sasl_certs')
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def add_cert(self, name, cert, allow_management=True, ifrom=None,
timeout=None, callback=None):
timeout=None, callback=None, timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['from'] = ifrom
iq['sasl_cert_append']['name'] = name
iq['sasl_cert_append']['x509cert'] = cert
iq['sasl_cert_append']['cert_management'] = allow_management
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def disable_cert(self, name, ifrom=None,
timeout=None, callback=None):
def disable_cert(self, name, ifrom=None, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['from'] = ifrom
iq['sasl_cert_disable']['name'] = name
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)
def revoke_cert(self, name, ifrom=None,
timeout=None, callback=None):
def revoke_cert(self, name, ifrom=None, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'set'
iq['from'] = ifrom
iq['sasl_cert_revoke']['name'] = name
return iq.send(timeout=timeout, callback=callback)
return iq.send(timeout=timeout, callback=callback,
timeout_callback=timeout_callback)

View File

@ -31,9 +31,11 @@ class XEP_0279(BasePlugin):
def plugin_end(self):
self.xmpp['xep_0030'].del_feature(feature='urn:xmpp:sic:0')
def check_ip(self, ifrom=None, block=True, timeout=None, callback=None):
def check_ip(self, ifrom=None, block=True, timeout=None, callback=None,
timeout_callback=None):
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq['from'] = ifrom
iq.enable('ip_check')
return iq.send(block=block, timeout=timeout, callback=callback)
return iq.send(block=block, timeout=timeout, callback=callback,
timeout_callback=timeout_callback)