Fix the iq.send() function, and a bunch of places where it is called
This is a big-and-dirty commit with a bunch of cleanup, maybe breaking a few things, and not fixing all iq.send() calls yet.
This commit is contained in:
parent
2e571ac950
commit
ab03ad54aa
@ -221,19 +221,11 @@ class ClientXMPP(BaseXMPP):
|
|||||||
"""
|
"""
|
||||||
return self.client_roster.remove(jid)
|
return self.client_roster.remove(jid)
|
||||||
|
|
||||||
def get_roster(self, block=True, timeout=None, callback=None):
|
def get_roster(self, callback=None, timeout=None, timeout_callback=None):
|
||||||
"""Request the roster from the server.
|
"""Request the roster from the server.
|
||||||
|
|
||||||
:param block: Specify if the roster request will block until a
|
:param callback: Reference to a stream handler function. Will
|
||||||
response is received, or a timeout occurs.
|
|
||||||
Defaults to ``True``.
|
|
||||||
:param timeout: The length of time (in seconds) to wait for a response
|
|
||||||
before continuing if blocking is used.
|
|
||||||
Defaults to
|
|
||||||
:attr:`~slixmpp.xmlstream.xmlstream.XMLStream.response_timeout`.
|
|
||||||
:param callback: Optional reference to a stream handler function. Will
|
|
||||||
be executed when the roster is received.
|
be executed when the roster is received.
|
||||||
Implies ``block=False``.
|
|
||||||
"""
|
"""
|
||||||
iq = self.Iq()
|
iq = self.Iq()
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
@ -241,9 +233,6 @@ class ClientXMPP(BaseXMPP):
|
|||||||
if 'rosterver' in self.features:
|
if 'rosterver' in self.features:
|
||||||
iq['roster']['ver'] = self.client_roster.version
|
iq['roster']['ver'] = self.client_roster.version
|
||||||
|
|
||||||
|
|
||||||
if not block or callback is not None:
|
|
||||||
block = False
|
|
||||||
if callback is None:
|
if callback is None:
|
||||||
callback = lambda resp: self.event('roster_update', resp)
|
callback = lambda resp: self.event('roster_update', resp)
|
||||||
else:
|
else:
|
||||||
@ -253,11 +242,7 @@ class ClientXMPP(BaseXMPP):
|
|||||||
orig_cb(resp)
|
orig_cb(resp)
|
||||||
callback = wrapped
|
callback = wrapped
|
||||||
|
|
||||||
response = iq.send(block, timeout, callback)
|
iq.send(callback, timeout, timeout_callback)
|
||||||
|
|
||||||
if block:
|
|
||||||
self.event('roster_update', response)
|
|
||||||
return response
|
|
||||||
|
|
||||||
def _reset_connection_state(self, event=None):
|
def _reset_connection_state(self, event=None):
|
||||||
#TODO: Use stream state here
|
#TODO: Use stream state here
|
||||||
|
@ -49,7 +49,7 @@ class FeatureBind(BasePlugin):
|
|||||||
if self.xmpp.requested_jid.resource:
|
if self.xmpp.requested_jid.resource:
|
||||||
iq['bind']['resource'] = self.xmpp.requested_jid.resource
|
iq['bind']['resource'] = self.xmpp.requested_jid.resource
|
||||||
|
|
||||||
iq.send(block=False, callback=self._on_bind_response)
|
iq.send(callback=self._on_bind_response)
|
||||||
|
|
||||||
def _on_bind_response(self, response):
|
def _on_bind_response(self, response):
|
||||||
self.xmpp.boundjid = JID(response['bind']['jid'], cache_lock=True)
|
self.xmpp.boundjid = JID(response['bind']['jid'], cache_lock=True)
|
||||||
|
@ -44,7 +44,7 @@ class FeatureSession(BasePlugin):
|
|||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq.enable('session')
|
iq.enable('session')
|
||||||
iq.send(block=False, callback=self._on_start_session_response)
|
iq.send(callback=self._on_start_session_response)
|
||||||
|
|
||||||
def _on_start_session_response(self, response):
|
def _on_start_session_response(self, response):
|
||||||
self.xmpp.features.add('session')
|
self.xmpp.features.add('session')
|
||||||
|
@ -76,8 +76,8 @@ class XEP_0012(BasePlugin):
|
|||||||
def del_last_activity(self, jid):
|
def del_last_activity(self, jid):
|
||||||
self.api['del_last_activity'](jid)
|
self.api['del_last_activity'](jid)
|
||||||
|
|
||||||
def get_last_activity(self, jid, local=False, ifrom=None, block=True,
|
def get_last_activity(self, jid, local=False, ifrom=None, timeout=None,
|
||||||
timeout=None, callback=None):
|
callback=None, timeout_callback=None):
|
||||||
if jid is not None and not isinstance(jid, JID):
|
if jid is not None and not isinstance(jid, JID):
|
||||||
jid = JID(jid)
|
jid = JID(jid)
|
||||||
|
|
||||||
@ -98,9 +98,8 @@ class XEP_0012(BasePlugin):
|
|||||||
iq['to'] = jid
|
iq['to'] = jid
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq.enable('last_activity')
|
iq.enable('last_activity')
|
||||||
return iq.send(timeout=timeout,
|
return iq.send(timeout=timeout, callback=callback,
|
||||||
block=block,
|
timeout_callback=timeout_callback)
|
||||||
callback=callback)
|
|
||||||
|
|
||||||
def _handle_get_last_activity(self, iq):
|
def _handle_get_last_activity(self, iq):
|
||||||
log.debug("Received last activity query from " + \
|
log.debug("Received last activity query from " + \
|
||||||
|
@ -48,7 +48,8 @@ class XEP_0013(BasePlugin):
|
|||||||
local=False,
|
local=False,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
def view(self, nodes, ifrom=None, block=True, timeout=None, callback=None):
|
def view(self, nodes, ifrom=None, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
if not isinstance(nodes, (list, set)):
|
if not isinstance(nodes, (list, set)):
|
||||||
nodes = [nodes]
|
nodes = [nodes]
|
||||||
|
|
||||||
@ -67,23 +68,16 @@ class XEP_0013(BasePlugin):
|
|||||||
StanzaPath('message/offline'))
|
StanzaPath('message/offline'))
|
||||||
self.xmpp.register_handler(collector)
|
self.xmpp.register_handler(collector)
|
||||||
|
|
||||||
if not block and callback is not None:
|
|
||||||
def wrapped_cb(iq):
|
def wrapped_cb(iq):
|
||||||
results = collector.stop()
|
results = collector.stop()
|
||||||
if iq['type'] == 'result':
|
if iq['type'] == 'result':
|
||||||
iq['offline']['results'] = results
|
iq['offline']['results'] = results
|
||||||
callback(iq)
|
callback(iq)
|
||||||
return iq.send(block=block, timeout=timeout, callback=wrapped_cb)
|
iq.send(timeout=timeout, callback=wrapped_cb,
|
||||||
else:
|
timeout_callback=timeout_callback)
|
||||||
try:
|
|
||||||
resp = iq.send(block=block, timeout=timeout, callback=callback)
|
|
||||||
resp['offline']['results'] = collector.stop()
|
|
||||||
return resp
|
|
||||||
except XMPPError as e:
|
|
||||||
collector.stop()
|
|
||||||
raise e
|
|
||||||
|
|
||||||
def remove(self, nodes, ifrom=None, block=True, timeout=None, callback=None):
|
def remove(self, nodes, ifrom=None, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
if not isinstance(nodes, (list, set)):
|
if not isinstance(nodes, (list, set)):
|
||||||
nodes = [nodes]
|
nodes = [nodes]
|
||||||
|
|
||||||
@ -97,9 +91,11 @@ class XEP_0013(BasePlugin):
|
|||||||
item['action'] = 'remove'
|
item['action'] = 'remove'
|
||||||
offline.append(item)
|
offline.append(item)
|
||||||
|
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def fetch(self, ifrom=None, block=True, timeout=None, callback=None):
|
def fetch(self, ifrom=None, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
@ -110,25 +106,19 @@ class XEP_0013(BasePlugin):
|
|||||||
StanzaPath('message/offline'))
|
StanzaPath('message/offline'))
|
||||||
self.xmpp.register_handler(collector)
|
self.xmpp.register_handler(collector)
|
||||||
|
|
||||||
if not block and callback is not None:
|
|
||||||
def wrapped_cb(iq):
|
def wrapped_cb(iq):
|
||||||
results = collector.stop()
|
results = collector.stop()
|
||||||
if iq['type'] == 'result':
|
if iq['type'] == 'result':
|
||||||
iq['offline']['results'] = results
|
iq['offline']['results'] = results
|
||||||
callback(iq)
|
callback(iq)
|
||||||
return iq.send(block=block, timeout=timeout, callback=wrapped_cb)
|
iq.send(timeout=timeout, callback=wrapped_cb,
|
||||||
else:
|
timeout_callback=timeout_callback)
|
||||||
try:
|
|
||||||
resp = iq.send(block=block, timeout=timeout, callback=callback)
|
|
||||||
resp['offline']['results'] = collector.stop()
|
|
||||||
return resp
|
|
||||||
except XMPPError as e:
|
|
||||||
collector.stop()
|
|
||||||
raise e
|
|
||||||
|
|
||||||
def purge(self, ifrom=None, block=True, timeout=None, callback=None):
|
def purge(self, ifrom=None, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
iq['offline']['purge'] = True
|
iq['offline']['purge'] = True
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
@ -29,55 +29,70 @@ class XEP_0016(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp['xep_0030'].add_feature(Privacy.namespace)
|
self.xmpp['xep_0030'].add_feature(Privacy.namespace)
|
||||||
|
|
||||||
def get_privacy_lists(self, block=True, timeout=None, callback=None):
|
def get_privacy_lists(self, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq.enable('privacy')
|
iq.enable('privacy')
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_list(self, name, block=True, timeout=None, callback=None):
|
def get_list(self, name, timeout=None, callback=None, timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['privacy']['list']['name'] = name
|
iq['privacy']['list']['name'] = name
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_active(self, block=True, timeout=None, callback=None):
|
def get_active(self, timeout=None, callback=None, timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['privacy'].enable('active')
|
iq['privacy'].enable('active')
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_default(self, block=True, timeout=None, callback=None):
|
def get_default(self, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['privacy'].enable('default')
|
iq['privacy'].enable('default')
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def activate(self, name, block=True, timeout=None, callback=None):
|
def activate(self, name, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['privacy']['active']['name'] = name
|
iq['privacy']['active']['name'] = name
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def deactivate(self, block=True, timeout=None, callback=None):
|
def deactivate(self, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['privacy'].enable('active')
|
iq['privacy'].enable('active')
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def make_default(self, name, block=True, timeout=None, callback=None):
|
def make_default(self, name, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['privacy']['default']['name'] = name
|
iq['privacy']['default']['name'] = name
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def remove_default(self, block=True, timeout=None, callback=None):
|
def remove_default(self, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['privacy'].enable('default')
|
iq['privacy'].enable('default')
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def edit_list(self, name, rules, block=True, timeout=None, callback=None):
|
def edit_list(self, name, rules, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['privacy']['list']['name'] = name
|
iq['privacy']['list']['name'] = name
|
||||||
@ -103,8 +118,10 @@ class XEP_0016(BasePlugin):
|
|||||||
presence_out=rule.get('presence_out',
|
presence_out=rule.get('presence_out',
|
||||||
rule.get('presence-out', None)))
|
rule.get('presence-out', None)))
|
||||||
|
|
||||||
def remove_list(self, name, block=True, timeout=None, callback=None):
|
def remove_list(self, name, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['privacy']['list']['name'] = name
|
iq['privacy']['list']['name'] = name
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
@ -317,10 +317,8 @@ class XEP_0030(BasePlugin):
|
|||||||
be skipped, even if a result has already been
|
be skipped, even if a result has already been
|
||||||
cached. Defaults to false.
|
cached. Defaults to false.
|
||||||
ifrom -- Specifiy the sender's JID.
|
ifrom -- Specifiy the sender's JID.
|
||||||
block -- If true, block and wait for the stanzas' reply.
|
timeout -- The time in seconds to wait for reply, before
|
||||||
timeout -- The time in seconds to block while waiting for
|
calling timeout_callback
|
||||||
a reply. If None, then wait indefinitely. The
|
|
||||||
timeout value is only used when block=True.
|
|
||||||
callback -- Optional callback to execute when a reply is
|
callback -- Optional callback to execute when a reply is
|
||||||
received instead of blocking and waiting for
|
received instead of blocking and waiting for
|
||||||
the reply.
|
the reply.
|
||||||
@ -364,8 +362,7 @@ class XEP_0030(BasePlugin):
|
|||||||
iq['to'] = jid
|
iq['to'] = jid
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['disco_info']['node'] = node if node else ''
|
iq['disco_info']['node'] = node if node else ''
|
||||||
return iq.send(timeout=kwargs.get('timeout', None),
|
iq.send(timeout=kwargs.get('timeout', None),
|
||||||
block=kwargs.get('block', True),
|
|
||||||
callback=kwargs.get('callback', None),
|
callback=kwargs.get('callback', None),
|
||||||
timeout_callback=kwargs.get('timeout_callback', None))
|
timeout_callback=kwargs.get('timeout_callback', None))
|
||||||
|
|
||||||
@ -399,7 +396,6 @@ class XEP_0030(BasePlugin):
|
|||||||
Otherwise, a disco stanza must be sent to the
|
Otherwise, a disco stanza must be sent to the
|
||||||
remove JID to retrieve the items.
|
remove JID to retrieve the items.
|
||||||
ifrom -- Specifiy the sender's JID.
|
ifrom -- Specifiy the sender's JID.
|
||||||
block -- If true, block and wait for the stanzas' reply.
|
|
||||||
timeout -- The time in seconds to block while waiting for
|
timeout -- The time in seconds to block while waiting for
|
||||||
a reply. If None, then wait indefinitely.
|
a reply. If None, then wait indefinitely.
|
||||||
callback -- Optional callback to execute when a reply is
|
callback -- Optional callback to execute when a reply is
|
||||||
@ -424,10 +420,10 @@ class XEP_0030(BasePlugin):
|
|||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['disco_items']['node'] = node if node else ''
|
iq['disco_items']['node'] = node if node else ''
|
||||||
if kwargs.get('iterator', False) and self.xmpp['xep_0059']:
|
if kwargs.get('iterator', False) and self.xmpp['xep_0059']:
|
||||||
|
raise NotImplementedError("XEP 0059 has not yet been fixed")
|
||||||
return self.xmpp['xep_0059'].iterate(iq, 'disco_items')
|
return self.xmpp['xep_0059'].iterate(iq, 'disco_items')
|
||||||
else:
|
else:
|
||||||
return iq.send(timeout=kwargs.get('timeout', None),
|
iq.send(timeout=kwargs.get('timeout', None),
|
||||||
block=kwargs.get('block', True),
|
|
||||||
callback=kwargs.get('callback', None),
|
callback=kwargs.get('callback', None),
|
||||||
timeout_callback=kwargs.get('timeout_callback', None))
|
timeout_callback=kwargs.get('timeout_callback', None))
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ class XEP_0049(BasePlugin):
|
|||||||
def register(self, stanza):
|
def register(self, stanza):
|
||||||
register_stanza_plugin(PrivateXML, stanza, iterable=True)
|
register_stanza_plugin(PrivateXML, stanza, iterable=True)
|
||||||
|
|
||||||
def store(self, data, ifrom=None, block=True, timeout=None, callback=None):
|
def store(self, data, ifrom=None, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'set'
|
iq['type'] = 'set'
|
||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
@ -43,11 +44,14 @@ class XEP_0049(BasePlugin):
|
|||||||
for elem in data:
|
for elem in data:
|
||||||
iq['private'].append(elem)
|
iq['private'].append(elem)
|
||||||
|
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
return iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def retrieve(self, name, ifrom=None, block=True, timeout=None, callback=None):
|
def retrieve(self, name, ifrom=None, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
iq = self.xmpp.Iq()
|
iq = self.xmpp.Iq()
|
||||||
iq['type'] = 'get'
|
iq['type'] = 'get'
|
||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
iq['private'].enable(name)
|
iq['private'].enable(name)
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
return iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
@ -104,17 +104,13 @@ class XEP_0050(BasePlugin):
|
|||||||
register_stanza_plugin(Command, Form)
|
register_stanza_plugin(Command, Form)
|
||||||
|
|
||||||
self.xmpp.add_event_handler('command_execute',
|
self.xmpp.add_event_handler('command_execute',
|
||||||
self._handle_command_start,
|
self._handle_command_start)
|
||||||
threaded=self.threaded)
|
|
||||||
self.xmpp.add_event_handler('command_next',
|
self.xmpp.add_event_handler('command_next',
|
||||||
self._handle_command_next,
|
self._handle_command_next)
|
||||||
threaded=self.threaded)
|
|
||||||
self.xmpp.add_event_handler('command_cancel',
|
self.xmpp.add_event_handler('command_cancel',
|
||||||
self._handle_command_cancel,
|
self._handle_command_cancel)
|
||||||
threaded=self.threaded)
|
|
||||||
self.xmpp.add_event_handler('command_complete',
|
self.xmpp.add_event_handler('command_complete',
|
||||||
self._handle_command_complete,
|
self._handle_command_complete)
|
||||||
threaded=self.threaded)
|
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp.del_event_handler('command_execute',
|
self.xmpp.del_event_handler('command_execute',
|
||||||
@ -450,7 +446,6 @@ class XEP_0050(BasePlugin):
|
|||||||
Otherwise, a disco stanza must be sent to the
|
Otherwise, a disco stanza must be sent to the
|
||||||
remove JID to retrieve the items.
|
remove JID to retrieve the items.
|
||||||
ifrom -- Specifiy the sender's JID.
|
ifrom -- Specifiy the sender's JID.
|
||||||
block -- If true, block and wait for the stanzas' reply.
|
|
||||||
timeout -- The time in seconds to block while waiting for
|
timeout -- The time in seconds to block while waiting for
|
||||||
a reply. If None, then wait indefinitely.
|
a reply. If None, then wait indefinitely.
|
||||||
callback -- Optional callback to execute when a reply is
|
callback -- Optional callback to execute when a reply is
|
||||||
@ -483,9 +478,6 @@ class XEP_0050(BasePlugin):
|
|||||||
command workflow methods contained in the
|
command workflow methods contained in the
|
||||||
session instead of returning the response
|
session instead of returning the response
|
||||||
stanza itself. Defaults to False.
|
stanza itself. Defaults to False.
|
||||||
block -- Specify if the send call will block until a
|
|
||||||
response is received, or a timeout occurs.
|
|
||||||
Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a
|
timeout -- The length of time (in seconds) to wait for a
|
||||||
response before exiting the send call
|
response before exiting the send call
|
||||||
if blocking is used. Defaults to
|
if blocking is used. Defaults to
|
||||||
@ -510,22 +502,12 @@ class XEP_0050(BasePlugin):
|
|||||||
if not flow:
|
if not flow:
|
||||||
return iq.send(**kwargs)
|
return iq.send(**kwargs)
|
||||||
else:
|
else:
|
||||||
if kwargs.get('block', True):
|
iq.send(callback=self._handle_command_result)
|
||||||
try:
|
|
||||||
result = iq.send(**kwargs)
|
|
||||||
except IqError as err:
|
|
||||||
result = err.iq
|
|
||||||
self._handle_command_result(result)
|
|
||||||
else:
|
|
||||||
iq.send(block=False, callback=self._handle_command_result)
|
|
||||||
|
|
||||||
def start_command(self, jid, node, session, ifrom=None, block=False):
|
def start_command(self, jid, node, session, ifrom=None):
|
||||||
"""
|
"""
|
||||||
Initiate executing a command provided by a remote agent.
|
Initiate executing a command provided by a remote agent.
|
||||||
|
|
||||||
The default workflow provided is non-blocking, but a blocking
|
|
||||||
version may be used with block=True.
|
|
||||||
|
|
||||||
The provided session dictionary should contain:
|
The provided session dictionary should contain:
|
||||||
next -- A handler for processing the command result.
|
next -- A handler for processing the command result.
|
||||||
error -- A handler for processing any error stanzas
|
error -- A handler for processing any error stanzas
|
||||||
@ -536,13 +518,10 @@ class XEP_0050(BasePlugin):
|
|||||||
node -- The node for the desired command.
|
node -- The node for the desired command.
|
||||||
session -- A dictionary of relevant session data.
|
session -- A dictionary of relevant session data.
|
||||||
ifrom -- Optionally specify the sender's JID.
|
ifrom -- Optionally specify the sender's JID.
|
||||||
block -- If True, block execution until a result
|
|
||||||
is received. Defaults to False.
|
|
||||||
"""
|
"""
|
||||||
session['jid'] = jid
|
session['jid'] = jid
|
||||||
session['node'] = node
|
session['node'] = node
|
||||||
session['timestamp'] = time.time()
|
session['timestamp'] = time.time()
|
||||||
session['block'] = block
|
|
||||||
if 'payload' not in session:
|
if 'payload' not in session:
|
||||||
session['payload'] = None
|
session['payload'] = None
|
||||||
|
|
||||||
@ -562,14 +541,7 @@ class XEP_0050(BasePlugin):
|
|||||||
sessionid = 'client:pending_' + iq['id']
|
sessionid = 'client:pending_' + iq['id']
|
||||||
session['id'] = sessionid
|
session['id'] = sessionid
|
||||||
self.sessions[sessionid] = session
|
self.sessions[sessionid] = session
|
||||||
if session['block']:
|
iq.send(callback=self._handle_command_result)
|
||||||
try:
|
|
||||||
result = iq.send(block=True)
|
|
||||||
except IqError as err:
|
|
||||||
result = err.iq
|
|
||||||
self._handle_command_result(result)
|
|
||||||
else:
|
|
||||||
iq.send(block=False, callback=self._handle_command_result)
|
|
||||||
|
|
||||||
def continue_command(self, session, direction='next'):
|
def continue_command(self, session, direction='next'):
|
||||||
"""
|
"""
|
||||||
@ -588,8 +560,7 @@ class XEP_0050(BasePlugin):
|
|||||||
action=direction,
|
action=direction,
|
||||||
payload=session.get('payload', None),
|
payload=session.get('payload', None),
|
||||||
sessionid=session['id'],
|
sessionid=session['id'],
|
||||||
flow=True,
|
flow=True)
|
||||||
block=session['block'])
|
|
||||||
|
|
||||||
def cancel_command(self, session):
|
def cancel_command(self, session):
|
||||||
"""
|
"""
|
||||||
@ -608,8 +579,7 @@ class XEP_0050(BasePlugin):
|
|||||||
action='cancel',
|
action='cancel',
|
||||||
payload=session.get('payload', None),
|
payload=session.get('payload', None),
|
||||||
sessionid=session['id'],
|
sessionid=session['id'],
|
||||||
flow=True,
|
flow=True)
|
||||||
block=session['block'])
|
|
||||||
|
|
||||||
def complete_command(self, session):
|
def complete_command(self, session):
|
||||||
"""
|
"""
|
||||||
@ -628,8 +598,7 @@ class XEP_0050(BasePlugin):
|
|||||||
action='complete',
|
action='complete',
|
||||||
payload=session.get('payload', None),
|
payload=session.get('payload', None),
|
||||||
sessionid=session['id'],
|
sessionid=session['id'],
|
||||||
flow=True,
|
flow=True)
|
||||||
block=session['block'])
|
|
||||||
|
|
||||||
def terminate_command(self, session):
|
def terminate_command(self, session):
|
||||||
"""
|
"""
|
||||||
|
@ -152,7 +152,7 @@ class XEP_0060(BasePlugin):
|
|||||||
self.node_event_map[node] = event_name
|
self.node_event_map[node] = event_name
|
||||||
|
|
||||||
def create_node(self, jid, node, config=None, ntype=None, ifrom=None,
|
def create_node(self, jid, node, config=None, ntype=None, ifrom=None,
|
||||||
block=True, callback=None, timeout=None):
|
timeout_callback=None, callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Create and configure a new pubsub node.
|
Create and configure a new pubsub node.
|
||||||
|
|
||||||
@ -174,8 +174,6 @@ class XEP_0060(BasePlugin):
|
|||||||
ntype -- The type of node to create. Servers typically default
|
ntype -- The type of node to create. Servers typically default
|
||||||
to using 'leaf' if no type is provided.
|
to using 'leaf' if no type is provided.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -200,10 +198,11 @@ class XEP_0060(BasePlugin):
|
|||||||
config.add_field(var='pubsub#node_type', value=ntype)
|
config.add_field(var='pubsub#node_type', value=ntype)
|
||||||
iq['pubsub']['configure'].append(config)
|
iq['pubsub']['configure'].append(config)
|
||||||
|
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def subscribe(self, jid, node, bare=True, subscribee=None, options=None,
|
def subscribe(self, jid, node, bare=True, subscribee=None, options=None,
|
||||||
ifrom=None, block=True, callback=None, timeout=None):
|
ifrom=None, timeout_callback=None, callback=None,
|
||||||
|
timeout=None):
|
||||||
"""
|
"""
|
||||||
Subscribe to updates from a pubsub node.
|
Subscribe to updates from a pubsub node.
|
||||||
|
|
||||||
@ -220,8 +219,6 @@ class XEP_0060(BasePlugin):
|
|||||||
subscribee -- The JID that is subscribing to the node.
|
subscribee -- The JID that is subscribing to the node.
|
||||||
options --
|
options --
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a
|
timeout -- The length of time (in seconds) to wait for a
|
||||||
response before exiting the send call if blocking
|
response before exiting the send call if blocking
|
||||||
is used.
|
is used.
|
||||||
@ -247,10 +244,11 @@ class XEP_0060(BasePlugin):
|
|||||||
iq['pubsub']['subscribe']['jid'] = subscribee
|
iq['pubsub']['subscribe']['jid'] = subscribee
|
||||||
if options is not None:
|
if options is not None:
|
||||||
iq['pubsub']['options'].append(options)
|
iq['pubsub']['options'].append(options)
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def unsubscribe(self, jid, node, subid=None, bare=True, subscribee=None,
|
def unsubscribe(self, jid, node, subid=None, bare=True, subscribee=None,
|
||||||
ifrom=None, block=True, callback=None, timeout=None):
|
ifrom=None, timeout_callback=None, callback=None,
|
||||||
|
timeout=None):
|
||||||
"""
|
"""
|
||||||
Unubscribe from updates from a pubsub node.
|
Unubscribe from updates from a pubsub node.
|
||||||
|
|
||||||
@ -269,8 +267,6 @@ class XEP_0060(BasePlugin):
|
|||||||
Defaults to True for a bare JID.
|
Defaults to True for a bare JID.
|
||||||
subscribee -- The JID that is subscribing to the node.
|
subscribee -- The JID that is subscribing to the node.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a
|
timeout -- The length of time (in seconds) to wait for a
|
||||||
response before exiting the send call if blocking
|
response before exiting the send call if blocking
|
||||||
is used.
|
is used.
|
||||||
@ -295,42 +291,43 @@ class XEP_0060(BasePlugin):
|
|||||||
|
|
||||||
iq['pubsub']['unsubscribe']['jid'] = subscribee
|
iq['pubsub']['unsubscribe']['jid'] = subscribee
|
||||||
iq['pubsub']['unsubscribe']['subid'] = subid
|
iq['pubsub']['unsubscribe']['subid'] = subid
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_subscriptions(self, jid, node=None, ifrom=None, block=True,
|
def get_subscriptions(self, jid, node=None, ifrom=None,
|
||||||
callback=None, timeout=None):
|
timeout_callback=None, callback=None,
|
||||||
|
timeout=None):
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
||||||
iq['pubsub']['subscriptions']['node'] = node
|
iq['pubsub']['subscriptions']['node'] = node
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_affiliations(self, jid, node=None, ifrom=None, block=True,
|
def get_affiliations(self, jid, node=None, ifrom=None,
|
||||||
callback=None, timeout=None):
|
timeout_callback=None, callback=None, timeout=None):
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
||||||
iq['pubsub']['affiliations']['node'] = node
|
iq['pubsub']['affiliations']['node'] = node
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_subscription_options(self, jid, node=None, user_jid=None,
|
def get_subscription_options(self, jid, node=None, user_jid=None,
|
||||||
ifrom=None, block=True, callback=None,
|
ifrom=None, timeout_callback=None,
|
||||||
timeout=None):
|
callback=None, timeout=None):
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
||||||
if user_jid is None:
|
if user_jid is None:
|
||||||
iq['pubsub']['default']['node'] = node
|
iq['pubsub']['default']['node'] = node
|
||||||
else:
|
else:
|
||||||
iq['pubsub']['options']['node'] = node
|
iq['pubsub']['options']['node'] = node
|
||||||
iq['pubsub']['options']['jid'] = user_jid
|
iq['pubsub']['options']['jid'] = user_jid
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def set_subscription_options(self, jid, node, user_jid, options,
|
def set_subscription_options(self, jid, node, user_jid, options,
|
||||||
ifrom=None, block=True, callback=None,
|
ifrom=None, timeout_callback=None,
|
||||||
timeout=None):
|
callback=None, timeout=None):
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
||||||
iq['pubsub']['options']['node'] = node
|
iq['pubsub']['options']['node'] = node
|
||||||
iq['pubsub']['options']['jid'] = user_jid
|
iq['pubsub']['options']['jid'] = user_jid
|
||||||
iq['pubsub']['options'].append(options)
|
iq['pubsub']['options'].append(options)
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_node_config(self, jid, node=None, ifrom=None, block=True,
|
def get_node_config(self, jid, node=None, ifrom=None,
|
||||||
callback=None, timeout=None):
|
timeout_callback=None, callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Retrieve the configuration for a node, or the pubsub service's
|
Retrieve the configuration for a node, or the pubsub service's
|
||||||
default configuration for new nodes.
|
default configuration for new nodes.
|
||||||
@ -341,8 +338,6 @@ class XEP_0060(BasePlugin):
|
|||||||
the default configuration for new nodes will be
|
the default configuration for new nodes will be
|
||||||
requested. Defaults to None.
|
requested. Defaults to None.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -354,10 +349,11 @@ class XEP_0060(BasePlugin):
|
|||||||
iq['pubsub_owner']['default']
|
iq['pubsub_owner']['default']
|
||||||
else:
|
else:
|
||||||
iq['pubsub_owner']['configure']['node'] = node
|
iq['pubsub_owner']['configure']['node'] = node
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_node_subscriptions(self, jid, node, ifrom=None, block=True,
|
def get_node_subscriptions(self, jid, node, ifrom=None,
|
||||||
callback=None, timeout=None):
|
timeout_callback=None, callback=None,
|
||||||
|
timeout=None):
|
||||||
"""
|
"""
|
||||||
Retrieve the subscriptions associated with a given node.
|
Retrieve the subscriptions associated with a given node.
|
||||||
|
|
||||||
@ -365,8 +361,6 @@ class XEP_0060(BasePlugin):
|
|||||||
jid -- The JID of the pubsub service.
|
jid -- The JID of the pubsub service.
|
||||||
node -- The node to retrieve subscriptions from.
|
node -- The node to retrieve subscriptions from.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -375,9 +369,9 @@ class XEP_0060(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
||||||
iq['pubsub_owner']['subscriptions']['node'] = node
|
iq['pubsub_owner']['subscriptions']['node'] = node
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_node_affiliations(self, jid, node, ifrom=None, block=True,
|
def get_node_affiliations(self, jid, node, ifrom=None, timeout_callback=None,
|
||||||
callback=None, timeout=None):
|
callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Retrieve the affiliations associated with a given node.
|
Retrieve the affiliations associated with a given node.
|
||||||
@ -386,8 +380,6 @@ class XEP_0060(BasePlugin):
|
|||||||
jid -- The JID of the pubsub service.
|
jid -- The JID of the pubsub service.
|
||||||
node -- The node to retrieve affiliations from.
|
node -- The node to retrieve affiliations from.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -396,10 +388,10 @@ class XEP_0060(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
||||||
iq['pubsub_owner']['affiliations']['node'] = node
|
iq['pubsub_owner']['affiliations']['node'] = node
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def delete_node(self, jid, node, ifrom=None, block=True,
|
def delete_node(self, jid, node, ifrom=None, timeout_callback=None, callback=None,
|
||||||
callback=None, timeout=None):
|
timeout=None):
|
||||||
"""
|
"""
|
||||||
Delete a a pubsub node.
|
Delete a a pubsub node.
|
||||||
|
|
||||||
@ -407,8 +399,6 @@ class XEP_0060(BasePlugin):
|
|||||||
jid -- The JID of the pubsub service.
|
jid -- The JID of the pubsub service.
|
||||||
node -- The node to delete.
|
node -- The node to delete.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -417,17 +407,18 @@ class XEP_0060(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
||||||
iq['pubsub_owner']['delete']['node'] = node
|
iq['pubsub_owner']['delete']['node'] = node
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def set_node_config(self, jid, node, config, ifrom=None, block=True,
|
def set_node_config(self, jid, node, config, ifrom=None,
|
||||||
callback=None, timeout=None):
|
timeout_callback=None, callback=None, timeout=None):
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
||||||
iq['pubsub_owner']['configure']['node'] = node
|
iq['pubsub_owner']['configure']['node'] = node
|
||||||
iq['pubsub_owner']['configure'].append(config)
|
iq['pubsub_owner']['configure'].append(config)
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def publish(self, jid, node, id=None, payload=None, options=None,
|
def publish(self, jid, node, id=None, payload=None, options=None,
|
||||||
ifrom=None, block=True, callback=None, timeout=None):
|
ifrom=None, timeout_callback=None, callback=None,
|
||||||
|
timeout=None):
|
||||||
"""
|
"""
|
||||||
Add a new item to a node, or edit an existing item.
|
Add a new item to a node, or edit an existing item.
|
||||||
|
|
||||||
@ -449,8 +440,6 @@ class XEP_0060(BasePlugin):
|
|||||||
payload -- The item content to publish.
|
payload -- The item content to publish.
|
||||||
options -- A form of publish options.
|
options -- A form of publish options.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -464,10 +453,10 @@ class XEP_0060(BasePlugin):
|
|||||||
if payload is not None:
|
if payload is not None:
|
||||||
iq['pubsub']['publish']['item']['payload'] = payload
|
iq['pubsub']['publish']['item']['payload'] = payload
|
||||||
iq['pubsub']['publish_options'] = options
|
iq['pubsub']['publish_options'] = options
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def retract(self, jid, node, id, notify=None, ifrom=None, block=True,
|
def retract(self, jid, node, id, notify=None, ifrom=None,
|
||||||
callback=None, timeout=None):
|
timeout_callback=None, callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Delete a single item from a node.
|
Delete a single item from a node.
|
||||||
"""
|
"""
|
||||||
@ -476,16 +465,16 @@ class XEP_0060(BasePlugin):
|
|||||||
iq['pubsub']['retract']['node'] = node
|
iq['pubsub']['retract']['node'] = node
|
||||||
iq['pubsub']['retract']['notify'] = notify
|
iq['pubsub']['retract']['notify'] = notify
|
||||||
iq['pubsub']['retract']['item']['id'] = id
|
iq['pubsub']['retract']['item']['id'] = id
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def purge(self, jid, node, ifrom=None, block=True, callback=None,
|
def purge(self, jid, node, ifrom=None, timeout_callback=None, callback=None,
|
||||||
timeout=None):
|
timeout=None):
|
||||||
"""
|
"""
|
||||||
Remove all items from a node.
|
Remove all items from a node.
|
||||||
"""
|
"""
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
||||||
iq['pubsub_owner']['purge']['node'] = node
|
iq['pubsub_owner']['purge']['node'] = node
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_nodes(self, *args, **kwargs):
|
def get_nodes(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -493,8 +482,8 @@ class XEP_0060(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
return self.xmpp['xep_0030'].get_items(*args, **kwargs)
|
return self.xmpp['xep_0030'].get_items(*args, **kwargs)
|
||||||
|
|
||||||
def get_item(self, jid, node, item_id, ifrom=None, block=True,
|
def get_item(self, jid, node, item_id, ifrom=None,
|
||||||
callback=None, timeout=None):
|
timeout_callback=None, callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Retrieve the content of an individual item.
|
Retrieve the content of an individual item.
|
||||||
"""
|
"""
|
||||||
@ -503,10 +492,10 @@ class XEP_0060(BasePlugin):
|
|||||||
item['id'] = item_id
|
item['id'] = item_id
|
||||||
iq['pubsub']['items']['node'] = node
|
iq['pubsub']['items']['node'] = node
|
||||||
iq['pubsub']['items'].append(item)
|
iq['pubsub']['items'].append(item)
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_items(self, jid, node, item_ids=None, max_items=None,
|
def get_items(self, jid, node, item_ids=None, max_items=None,
|
||||||
iterator=False, ifrom=None, block=False,
|
iterator=False, ifrom=None, timeout_callback=None,
|
||||||
callback=None, timeout=None):
|
callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Request the contents of a node's items.
|
Request the contents of a node's items.
|
||||||
@ -530,22 +519,21 @@ class XEP_0060(BasePlugin):
|
|||||||
if iterator:
|
if iterator:
|
||||||
return self.xmpp['xep_0059'].iterate(iq, 'pubsub')
|
return self.xmpp['xep_0059'].iterate(iq, 'pubsub')
|
||||||
else:
|
else:
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def get_item_ids(self, jid, node, ifrom=None, block=True,
|
def get_item_ids(self, jid, node, ifrom=None, timeout_callback=None, callback=None,
|
||||||
callback=None, timeout=None, iterator=False):
|
timeout=None, iterator=False):
|
||||||
"""
|
"""
|
||||||
Retrieve the ItemIDs hosted by a given node, using disco.
|
Retrieve the ItemIDs hosted by a given node, using disco.
|
||||||
"""
|
"""
|
||||||
return self.xmpp['xep_0030'].get_items(jid, node,
|
self.xmpp['xep_0030'].get_items(jid, node, ifrom=ifrom,
|
||||||
ifrom=ifrom,
|
callback=callback, timeout=timeout,
|
||||||
block=block,
|
iterator=iterator,
|
||||||
callback=callback,
|
timeout_callback=timeout_callback)
|
||||||
timeout=timeout,
|
|
||||||
iterator=iterator)
|
|
||||||
|
|
||||||
def modify_affiliations(self, jid, node, affiliations=None, ifrom=None,
|
def modify_affiliations(self, jid, node, affiliations=None, ifrom=None,
|
||||||
block=True, callback=None, timeout=None):
|
timeout_callback=None, callback=None,
|
||||||
|
timeout=None):
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
||||||
iq['pubsub_owner']['affiliations']['node'] = node
|
iq['pubsub_owner']['affiliations']['node'] = node
|
||||||
|
|
||||||
@ -558,10 +546,11 @@ class XEP_0060(BasePlugin):
|
|||||||
aff['affiliation'] = affiliation
|
aff['affiliation'] = affiliation
|
||||||
iq['pubsub_owner']['affiliations'].append(aff)
|
iq['pubsub_owner']['affiliations'].append(aff)
|
||||||
|
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def modify_subscriptions(self, jid, node, subscriptions=None, ifrom=None,
|
def modify_subscriptions(self, jid, node, subscriptions=None,
|
||||||
block=True, callback=None, timeout=None):
|
ifrom=None, timeout_callback=None,
|
||||||
|
callback=None, timeout=None):
|
||||||
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
||||||
iq['pubsub_owner']['subscriptions']['node'] = node
|
iq['pubsub_owner']['subscriptions']['node'] = node
|
||||||
|
|
||||||
@ -574,4 +563,4 @@ class XEP_0060(BasePlugin):
|
|||||||
sub['subscription'] = subscription
|
sub['subscription'] = subscription
|
||||||
iq['pubsub_owner']['subscriptions'].append(sub)
|
iq['pubsub_owner']['subscriptions'].append(sub)
|
||||||
|
|
||||||
return iq.send(block=block, callback=callback, timeout=timeout)
|
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)
|
||||||
|
@ -89,7 +89,7 @@ class XEP_0077(BasePlugin):
|
|||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
iq.enable('register')
|
iq.enable('register')
|
||||||
return iq.send(block=block, timeout=timeout,
|
return iq.send(block=block, timeout=timeout,
|
||||||
callback=callback, now=True)
|
callback=callback)
|
||||||
|
|
||||||
def cancel_registration(self, jid=None, ifrom=None, block=True,
|
def cancel_registration(self, jid=None, ifrom=None, block=True,
|
||||||
timeout=None, callback=None):
|
timeout=None, callback=None):
|
||||||
|
@ -79,7 +79,7 @@ class XEP_0078(BasePlugin):
|
|||||||
iq['auth']['username'] = self.xmpp.requested_jid.user
|
iq['auth']['username'] = self.xmpp.requested_jid.user
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = iq.send(now=True)
|
resp = iq.send()
|
||||||
except IqError as err:
|
except IqError as err:
|
||||||
log.info("Authentication failed: %s", err.iq['error']['condition'])
|
log.info("Authentication failed: %s", err.iq['error']['condition'])
|
||||||
self.xmpp.event('failed_auth')
|
self.xmpp.event('failed_auth')
|
||||||
@ -120,7 +120,7 @@ class XEP_0078(BasePlugin):
|
|||||||
|
|
||||||
# Step 3: Send credentials
|
# Step 3: Send credentials
|
||||||
try:
|
try:
|
||||||
result = iq.send(now=True)
|
result = iq.send()
|
||||||
except IqError as err:
|
except IqError as err:
|
||||||
log.info("Authentication failed")
|
log.info("Authentication failed")
|
||||||
self.xmpp.event("failed_auth")
|
self.xmpp.event("failed_auth")
|
||||||
|
@ -40,8 +40,8 @@ class XEP_0107(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp['xep_0163'].register_pep('user_mood', UserMood)
|
self.xmpp['xep_0163'].register_pep('user_mood', UserMood)
|
||||||
|
|
||||||
def publish_mood(self, value=None, text=None, options=None,
|
def publish_mood(self, value=None, text=None, options=None, ifrom=None,
|
||||||
ifrom=None, block=True, callback=None, timeout=None):
|
callback=None, timeout=None, timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Publish the user's current mood.
|
Publish the user's current mood.
|
||||||
|
|
||||||
@ -51,8 +51,6 @@ class XEP_0107(BasePlugin):
|
|||||||
for the mood.
|
for the mood.
|
||||||
options -- Optional form of publish options.
|
options -- Optional form of publish options.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -62,22 +60,18 @@ class XEP_0107(BasePlugin):
|
|||||||
mood = UserMood()
|
mood = UserMood()
|
||||||
mood['value'] = value
|
mood['value'] = value
|
||||||
mood['text'] = text
|
mood['text'] = text
|
||||||
return self.xmpp['xep_0163'].publish(mood,
|
self.xmpp['xep_0163'].publish(mood, node=UserMood.namespace,
|
||||||
node=UserMood.namespace,
|
options=options, ifrom=ifrom,
|
||||||
options=options,
|
callback=callback, timeout=timeout,
|
||||||
ifrom=ifrom,
|
timeout_callback=timeout_callback)
|
||||||
block=block,
|
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
|
||||||
def stop(self, ifrom=None, block=True, callback=None, timeout=None):
|
def stop(self, ifrom=None, callback=None, timeout=None,
|
||||||
|
timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Clear existing user mood information to stop notifications.
|
Clear existing user mood information to stop notifications.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -85,9 +79,7 @@ class XEP_0107(BasePlugin):
|
|||||||
be executed when a reply stanza is received.
|
be executed when a reply stanza is received.
|
||||||
"""
|
"""
|
||||||
mood = UserMood()
|
mood = UserMood()
|
||||||
return self.xmpp['xep_0163'].publish(mood,
|
self.xmpp['xep_0163'].publish(mood, node=UserMood.namespace,
|
||||||
node=UserMood.namespace,
|
ifrom=ifrom, callback=callback,
|
||||||
ifrom=ifrom,
|
timeout=timeout,
|
||||||
block=block,
|
timeout_callback=timeout_callback)
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
@ -33,8 +33,9 @@ class XEP_0108(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp['xep_0163'].register_pep('user_activity', UserActivity)
|
self.xmpp['xep_0163'].register_pep('user_activity', UserActivity)
|
||||||
|
|
||||||
def publish_activity(self, general, specific=None, text=None, options=None,
|
def publish_activity(self, general, specific=None, text=None,
|
||||||
ifrom=None, block=True, callback=None, timeout=None):
|
options=None, ifrom=None, callback=None,
|
||||||
|
timeout=None, timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Publish the user's current activity.
|
Publish the user's current activity.
|
||||||
|
|
||||||
@ -46,8 +47,6 @@ class XEP_0108(BasePlugin):
|
|||||||
for the activity.
|
for the activity.
|
||||||
options -- Optional form of publish options.
|
options -- Optional form of publish options.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -57,22 +56,19 @@ class XEP_0108(BasePlugin):
|
|||||||
activity = UserActivity()
|
activity = UserActivity()
|
||||||
activity['value'] = (general, specific)
|
activity['value'] = (general, specific)
|
||||||
activity['text'] = text
|
activity['text'] = text
|
||||||
return self.xmpp['xep_0163'].publish(activity,
|
self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace,
|
||||||
node=UserActivity.namespace,
|
options=options, ifrom=ifrom,
|
||||||
options=options,
|
|
||||||
ifrom=ifrom,
|
|
||||||
block=block,
|
|
||||||
callback=callback,
|
callback=callback,
|
||||||
timeout=timeout)
|
timeout=timeout,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def stop(self, ifrom=None, block=True, callback=None, timeout=None):
|
def stop(self, ifrom=None, callback=None, timeout=None,
|
||||||
|
timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Clear existing user activity information to stop notifications.
|
Clear existing user activity information to stop notifications.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -80,9 +76,7 @@ class XEP_0108(BasePlugin):
|
|||||||
be executed when a reply stanza is received.
|
be executed when a reply stanza is received.
|
||||||
"""
|
"""
|
||||||
activity = UserActivity()
|
activity = UserActivity()
|
||||||
return self.xmpp['xep_0163'].publish(activity,
|
self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace,
|
||||||
node=UserActivity.namespace,
|
ifrom=ifrom, callback=callback,
|
||||||
ifrom=ifrom,
|
timeout=timeout,
|
||||||
block=block,
|
timeout_callback=timeout_callback)
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
import threading
|
|
||||||
|
|
||||||
from slixmpp import __version__
|
from slixmpp import __version__
|
||||||
from slixmpp.stanza import StreamFeatures, Presence, Iq
|
from slixmpp.stanza import StreamFeatures, Presence, Iq
|
||||||
@ -65,8 +64,7 @@ class XEP_0115(BasePlugin):
|
|||||||
|
|
||||||
self.xmpp.add_filter('out', self._filter_add_caps)
|
self.xmpp.add_filter('out', self._filter_add_caps)
|
||||||
|
|
||||||
self.xmpp.add_event_handler('entity_caps', self._process_caps,
|
self.xmpp.add_event_handler('entity_caps', self._process_caps)
|
||||||
threaded=True)
|
|
||||||
|
|
||||||
if not self.xmpp.is_component:
|
if not self.xmpp.is_component:
|
||||||
self.xmpp.register_feature('caps',
|
self.xmpp.register_feature('caps',
|
||||||
@ -90,9 +88,6 @@ class XEP_0115(BasePlugin):
|
|||||||
disco.assign_verstring = self.assign_verstring
|
disco.assign_verstring = self.assign_verstring
|
||||||
disco.get_verstring = self.get_verstring
|
disco.get_verstring = self.get_verstring
|
||||||
|
|
||||||
self._processing_lock = threading.Lock()
|
|
||||||
self._processing = set()
|
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp['xep_0030'].del_feature(feature=stanza.Capabilities.namespace)
|
self.xmpp['xep_0030'].del_feature(feature=stanza.Capabilities.namespace)
|
||||||
self.xmpp.del_filter('out', self._filter_add_caps)
|
self.xmpp.del_filter('out', self._filter_add_caps)
|
||||||
@ -164,13 +159,6 @@ class XEP_0115(BasePlugin):
|
|||||||
except XMPPError:
|
except XMPPError:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Only lookup the same caps once at a time.
|
|
||||||
with self._processing_lock:
|
|
||||||
if ver in self._processing:
|
|
||||||
log.debug('Already processing verstring %s' % ver)
|
|
||||||
return
|
|
||||||
self._processing.add(ver)
|
|
||||||
|
|
||||||
log.debug("New caps verification string: %s", ver)
|
log.debug("New caps verification string: %s", ver)
|
||||||
try:
|
try:
|
||||||
node = '%s#%s' % (pres['caps']['node'], ver)
|
node = '%s#%s' % (pres['caps']['node'], ver)
|
||||||
@ -185,9 +173,6 @@ class XEP_0115(BasePlugin):
|
|||||||
except XMPPError:
|
except XMPPError:
|
||||||
log.debug("Could not retrieve disco#info results for caps for %s", node)
|
log.debug("Could not retrieve disco#info results for caps for %s", node)
|
||||||
|
|
||||||
with self._processing_lock:
|
|
||||||
self._processing.remove(ver)
|
|
||||||
|
|
||||||
def _validate_caps(self, caps, hash, check_verstring):
|
def _validate_caps(self, caps, hash, check_verstring):
|
||||||
# Check Identities
|
# Check Identities
|
||||||
full_ids = caps.get_identities(dedupe=False)
|
full_ids = caps.get_identities(dedupe=False)
|
||||||
|
@ -83,7 +83,7 @@ class XEP_0163(BasePlugin):
|
|||||||
self.xmpp['xep_0115'].update_caps(jid)
|
self.xmpp['xep_0115'].update_caps(jid)
|
||||||
|
|
||||||
def publish(self, stanza, node=None, id=None, options=None, ifrom=None,
|
def publish(self, stanza, node=None, id=None, options=None, ifrom=None,
|
||||||
block=True, callback=None, timeout=None):
|
timeout_callback=None, callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Publish a PEP update.
|
Publish a PEP update.
|
||||||
|
|
||||||
@ -97,8 +97,6 @@ class XEP_0163(BasePlugin):
|
|||||||
id -- Optionally specify the ID of the item.
|
id -- Optionally specify the ID of the item.
|
||||||
options -- A form of publish options.
|
options -- A form of publish options.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -110,14 +108,12 @@ class XEP_0163(BasePlugin):
|
|||||||
if id is None:
|
if id is None:
|
||||||
id = 'current'
|
id = 'current'
|
||||||
|
|
||||||
return self.xmpp['xep_0060'].publish(ifrom, node,
|
return self.xmpp['xep_0060'].publish(ifrom, node, id=id,
|
||||||
id=id,
|
|
||||||
payload=stanza.xml,
|
payload=stanza.xml,
|
||||||
options=options,
|
options=options, ifrom=ifrom,
|
||||||
ifrom=ifrom,
|
|
||||||
block=block,
|
|
||||||
callback=callback,
|
callback=callback,
|
||||||
timeout=timeout)
|
timeout=timeout,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
|
|
||||||
register_plugin(XEP_0163)
|
register_plugin(XEP_0163)
|
||||||
|
@ -42,7 +42,7 @@ class XEP_0172(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp['xep_0163'].register_pep('user_nick', UserNick)
|
self.xmpp['xep_0163'].register_pep('user_nick', UserNick)
|
||||||
|
|
||||||
def publish_nick(self, nick=None, options=None, ifrom=None, block=True,
|
def publish_nick(self, nick=None, options=None, ifrom=None, timeout_callback=None,
|
||||||
callback=None, timeout=None):
|
callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Publish the user's current nick.
|
Publish the user's current nick.
|
||||||
@ -51,8 +51,6 @@ class XEP_0172(BasePlugin):
|
|||||||
nick -- The user nickname to publish.
|
nick -- The user nickname to publish.
|
||||||
options -- Optional form of publish options.
|
options -- Optional form of publish options.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -61,22 +59,17 @@ class XEP_0172(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
nickname = UserNick()
|
nickname = UserNick()
|
||||||
nickname['nick'] = nick
|
nickname['nick'] = nick
|
||||||
return self.xmpp['xep_0163'].publish(nickname,
|
self.xmpp['xep_0163'].publish(nickname, node=UserNick.namespace,
|
||||||
node=UserNick.namespace,
|
options=options, ifrom=ifrom,
|
||||||
options=options,
|
callback=callback, timeout=timeout,
|
||||||
ifrom=ifrom,
|
timeout_callback=timeout_callback)
|
||||||
block=block,
|
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
|
||||||
def stop(self, ifrom=None, block=True, callback=None, timeout=None):
|
def stop(self, ifrom=None, timeout_callback=None, callback=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Clear existing user nick information to stop notifications.
|
Clear existing user nick information to stop notifications.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -84,9 +77,7 @@ class XEP_0172(BasePlugin):
|
|||||||
be executed when a reply stanza is received.
|
be executed when a reply stanza is received.
|
||||||
"""
|
"""
|
||||||
nick = UserNick()
|
nick = UserNick()
|
||||||
return self.xmpp['xep_0163'].publish(nick,
|
return self.xmpp['xep_0163'].publish(nick, node=UserNick.namespace,
|
||||||
node=UserNick.namespace,
|
ifrom=ifrom, callback=callback,
|
||||||
ifrom=ifrom,
|
timeout=timeout,
|
||||||
block=block,
|
timeout_callback=timeout_callback)
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
@ -33,9 +33,11 @@ class XEP_0196(BasePlugin):
|
|||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.xmpp['xep_0163'].register_pep('user_gaming', UserGaming)
|
self.xmpp['xep_0163'].register_pep('user_gaming', UserGaming)
|
||||||
|
|
||||||
def publish_gaming(self, name=None, level=None, server_name=None, uri=None,
|
def publish_gaming(self, name=None, level=None, server_name=None,
|
||||||
character_name=None, character_profile=None, server_address=None,
|
uri=None, character_name=None,
|
||||||
options=None, ifrom=None, block=True, callback=None, timeout=None):
|
character_profile=None, server_address=None,
|
||||||
|
options=None, ifrom=None, callback=None,
|
||||||
|
timeout=None, timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Publish the user's current gaming status.
|
Publish the user's current gaming status.
|
||||||
|
|
||||||
@ -50,8 +52,6 @@ class XEP_0196(BasePlugin):
|
|||||||
character_profile -- A URI for a profile of the user's character.
|
character_profile -- A URI for a profile of the user's character.
|
||||||
options -- Optional form of publish options.
|
options -- Optional form of publish options.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -68,20 +68,17 @@ class XEP_0196(BasePlugin):
|
|||||||
gaming['server_address'] = server_address
|
gaming['server_address'] = server_address
|
||||||
return self.xmpp['xep_0163'].publish(gaming,
|
return self.xmpp['xep_0163'].publish(gaming,
|
||||||
node=UserGaming.namespace,
|
node=UserGaming.namespace,
|
||||||
options=options,
|
options=options, ifrom=ifrom,
|
||||||
ifrom=ifrom,
|
callback=callback, timeout=timeout,
|
||||||
block=block,
|
timeout_callback=timeout_callback)
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
|
||||||
def stop(self, ifrom=None, block=True, callback=None, timeout=None):
|
def stop(self, ifrom=None, callback=None, timeout=None,
|
||||||
|
timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Clear existing user gaming information to stop notifications.
|
Clear existing user gaming information to stop notifications.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -91,7 +88,6 @@ class XEP_0196(BasePlugin):
|
|||||||
gaming = UserGaming()
|
gaming = UserGaming()
|
||||||
return self.xmpp['xep_0163'].publish(gaming,
|
return self.xmpp['xep_0163'].publish(gaming,
|
||||||
node=UserGaming.namespace,
|
node=UserGaming.namespace,
|
||||||
ifrom=ifrom,
|
ifrom=ifrom, callback=callback,
|
||||||
block=block,
|
timeout=timeout,
|
||||||
callback=callback,
|
timeout_callback=timeout_callback)
|
||||||
timeout=timeout)
|
|
||||||
|
@ -101,7 +101,7 @@ class XEP_0199(BasePlugin):
|
|||||||
repeat=True)
|
repeat=True)
|
||||||
|
|
||||||
def disable_keepalive(self, event=None):
|
def disable_keepalive(self, event=None):
|
||||||
self.xmpp.scheduler.remove('Ping keepalive')
|
self.xmpp.cancel_schedule('Ping keepalive')
|
||||||
|
|
||||||
def _keepalive(self, event=None):
|
def _keepalive(self, event=None):
|
||||||
log.debug("Keepalive ping...")
|
log.debug("Keepalive ping...")
|
||||||
@ -119,15 +119,13 @@ class XEP_0199(BasePlugin):
|
|||||||
log.debug("Pinged by %s", iq['from'])
|
log.debug("Pinged by %s", iq['from'])
|
||||||
iq.reply().send()
|
iq.reply().send()
|
||||||
|
|
||||||
def send_ping(self, jid, ifrom=None, block=True, timeout=None, callback=None):
|
def send_ping(self, jid, ifrom=None, timeout=None, callback=None,
|
||||||
|
timeout_callback=None):
|
||||||
"""Send a ping request.
|
"""Send a ping request.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
jid -- The JID that will receive the ping.
|
jid -- The JID that will receive the ping.
|
||||||
ifrom -- Specifiy the sender JID.
|
ifrom -- Specifiy the sender JID.
|
||||||
block -- Indicate if execution should block until
|
|
||||||
a pong response is received. Defaults
|
|
||||||
to True.
|
|
||||||
timeout -- Time in seconds to wait for a response.
|
timeout -- Time in seconds to wait for a response.
|
||||||
Defaults to self.timeout.
|
Defaults to self.timeout.
|
||||||
callback -- Optional handler to execute when a pong
|
callback -- Optional handler to execute when a pong
|
||||||
@ -143,7 +141,8 @@ class XEP_0199(BasePlugin):
|
|||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
iq.enable('ping')
|
iq.enable('ping')
|
||||||
|
|
||||||
return iq.send(block=block, timeout=timeout, callback=callback)
|
return iq.send(timeout=timeout, callback=callback,
|
||||||
|
timeout_callback=timeout_callback)
|
||||||
|
|
||||||
def ping(self, jid=None, ifrom=None, timeout=None):
|
def ping(self, jid=None, ifrom=None, timeout=None):
|
||||||
"""Send a ping request and calculate RTT.
|
"""Send a ping request and calculate RTT.
|
||||||
|
@ -32,6 +32,7 @@ class XEP_0223(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
Update a node's configuration to match the public storage profile.
|
Update a node's configuration to match the public storage profile.
|
||||||
"""
|
"""
|
||||||
|
# TODO: that cannot possibly work, why is this here?
|
||||||
config = self.xmpp['xep_0004'].Form()
|
config = self.xmpp['xep_0004'].Form()
|
||||||
config['type'] = 'submit'
|
config['type'] = 'submit'
|
||||||
|
|
||||||
@ -40,12 +41,11 @@ class XEP_0223(BasePlugin):
|
|||||||
|
|
||||||
return self.xmpp['xep_0060'].set_node_config(None, node, config,
|
return self.xmpp['xep_0060'].set_node_config(None, node, config,
|
||||||
ifrom=ifrom,
|
ifrom=ifrom,
|
||||||
block=block,
|
|
||||||
callback=callback,
|
callback=callback,
|
||||||
timeout=timeout)
|
timeout=timeout)
|
||||||
|
|
||||||
def store(self, stanza, node=None, id=None, ifrom=None, options=None,
|
def store(self, stanza, node=None, id=None, ifrom=None, options=None,
|
||||||
block=True, callback=None, timeout=None):
|
callback=None, timeout=None, timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Store private data via PEP.
|
Store private data via PEP.
|
||||||
|
|
||||||
@ -60,8 +60,6 @@ class XEP_0223(BasePlugin):
|
|||||||
options -- Publish options to use, which will be modified to
|
options -- Publish options to use, which will be modified to
|
||||||
fit the persistent storage option profile.
|
fit the persistent storage option profile.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -82,15 +80,13 @@ class XEP_0223(BasePlugin):
|
|||||||
options.add_field(var=field)
|
options.add_field(var=field)
|
||||||
options['fields'][field]['value'] = value
|
options['fields'][field]['value'] = value
|
||||||
|
|
||||||
return self.xmpp['xep_0163'].publish(stanza, node,
|
return self.xmpp['xep_0163'].publish(stanza, node, options=options,
|
||||||
options=options,
|
ifrom=ifrom, callback=callback,
|
||||||
ifrom=ifrom,
|
timeout=timeout,
|
||||||
block=block,
|
timeout_callback=timeout_callback)
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
|
||||||
def retrieve(self, node, id=None, item_ids=None, ifrom=None,
|
def retrieve(self, node, id=None, item_ids=None, ifrom=None,
|
||||||
block=True, callback=None, timeout=None):
|
callback=None, timeout=None, timeout_callback=None):
|
||||||
"""
|
"""
|
||||||
Retrieve private data via PEP.
|
Retrieve private data via PEP.
|
||||||
|
|
||||||
@ -103,8 +99,6 @@ class XEP_0223(BasePlugin):
|
|||||||
item_ids -- Specify a group of IDs. If id is also specified, it
|
item_ids -- Specify a group of IDs. If id is also specified, it
|
||||||
will be included in item_ids.
|
will be included in item_ids.
|
||||||
ifrom -- Specify the sender's JID.
|
ifrom -- Specify the sender's JID.
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
timeout -- The length of time (in seconds) to wait for a response
|
||||||
before exiting the send call if blocking is used.
|
before exiting the send call if blocking is used.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||||
@ -117,11 +111,9 @@ class XEP_0223(BasePlugin):
|
|||||||
item_ids.append(id)
|
item_ids.append(id)
|
||||||
|
|
||||||
return self.xmpp['xep_0060'].get_items(None, node,
|
return self.xmpp['xep_0060'].get_items(None, node,
|
||||||
item_ids=item_ids,
|
item_ids=item_ids, ifrom=ifrom,
|
||||||
ifrom=ifrom,
|
callback=callback, timeout=timeout,
|
||||||
block=block,
|
timeout_callback=timeout_callback)
|
||||||
callback=callback,
|
|
||||||
timeout=timeout)
|
|
||||||
|
|
||||||
|
|
||||||
register_plugin(XEP_0223)
|
register_plugin(XEP_0223)
|
||||||
|
@ -158,38 +158,26 @@ class Iq(RootStanza):
|
|||||||
StanzaBase.reply(self, clear)
|
StanzaBase.reply(self, clear)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def send(self, block=True, timeout=None, callback=None, now=False, timeout_callback=None):
|
def send(self, callback=None, timeout=None, timeout_callback=None):
|
||||||
"""
|
"""Send an <iq> stanza over the XML stream.
|
||||||
Send an <iq> stanza over the XML stream.
|
|
||||||
|
|
||||||
The send call can optionally block until a response is received or
|
A callback handler can be provided that will be executed when the Iq
|
||||||
a timeout occurs. Be aware that using blocking in non-threaded event
|
stanza's result reply is received.
|
||||||
handlers can drastically impact performance. Otherwise, a callback
|
|
||||||
handler can be provided that will be executed when the Iq stanza's
|
|
||||||
result reply is received. Be aware though that that the callback
|
|
||||||
handler will not be executed in its own thread.
|
|
||||||
|
|
||||||
Using both block and callback is not recommended, and only the
|
|
||||||
callback argument will be used in that case.
|
|
||||||
|
|
||||||
Overrides StanzaBase.send
|
Overrides StanzaBase.send
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
block -- Specify if the send call will block until a response
|
|
||||||
is received, or a timeout occurs. Defaults to True.
|
callback -- Optional reference to a stream handler
|
||||||
timeout -- The length of time (in seconds) to wait for a response
|
function. Will be executed when a reply stanza is
|
||||||
before exiting the send call if blocking is used.
|
received.
|
||||||
Defaults to slixmpp.xmlstream.RESPONSE_TIMEOUT
|
timeout -- The length of time (in seconds) to wait for a
|
||||||
callback -- Optional reference to a stream handler function. Will
|
response before the timeout_callback is called,
|
||||||
be executed when a reply stanza is received.
|
instead of the regular callback
|
||||||
now -- Indicates if the send queue should be skipped and send
|
timeout_callback -- Optional reference to a stream handler
|
||||||
the stanza immediately. Used during stream
|
function. Will be executed when the timeout expires
|
||||||
initialization. Defaults to False.
|
before a response has been received with the
|
||||||
timeout_callback -- Optional reference to a stream handler function.
|
originally-sent IQ stanza.
|
||||||
Will be executed when the timeout expires before a
|
|
||||||
response has been received with the originally-sent IQ
|
|
||||||
stanza. Only called if there is a callback parameter
|
|
||||||
(and therefore are in async mode).
|
|
||||||
"""
|
"""
|
||||||
if self.stream.session_bind_event.is_set():
|
if self.stream.session_bind_event.is_set():
|
||||||
matcher = MatchIDSender({
|
matcher = MatchIDSender({
|
||||||
@ -219,24 +207,14 @@ class Iq(RootStanza):
|
|||||||
callback,
|
callback,
|
||||||
once=True)
|
once=True)
|
||||||
self.stream.register_handler(handler)
|
self.stream.register_handler(handler)
|
||||||
StanzaBase.send(self, now=now)
|
StanzaBase.send(self)
|
||||||
return handler_name
|
return handler_name
|
||||||
elif block and self['type'] in ('get', 'set'):
|
|
||||||
waitfor = Waiter('IqWait_%s' % self['id'], matcher)
|
|
||||||
self.stream.register_handler(waitfor)
|
|
||||||
StanzaBase.send(self, now=now)
|
|
||||||
result = waitfor.wait(timeout)
|
|
||||||
if not result:
|
|
||||||
raise IqTimeout(self)
|
|
||||||
if result['type'] == 'error':
|
|
||||||
raise IqError(result)
|
|
||||||
return result
|
|
||||||
else:
|
else:
|
||||||
return StanzaBase.send(self, now=now)
|
return StanzaBase.send(self)
|
||||||
|
|
||||||
def _handle_result(self, iq):
|
def _handle_result(self, iq):
|
||||||
# we got the IQ, so don't fire the timeout
|
# we got the IQ, so don't fire the timeout
|
||||||
self.stream.scheduler.remove('IqTimeout_%s' % self['id'])
|
self.stream.cancel_schedule('IqTimeout_%s' % self['id'])
|
||||||
self.callback(iq)
|
self.callback(iq)
|
||||||
|
|
||||||
def _fire_timeout(self):
|
def _fire_timeout(self):
|
||||||
|
@ -1573,7 +1573,7 @@ class StanzaBase(ElementBase):
|
|||||||
log.exception('Error handling {%s}%s stanza', self.namespace,
|
log.exception('Error handling {%s}%s stanza', self.namespace,
|
||||||
self.name)
|
self.name)
|
||||||
|
|
||||||
def send(self, now=False):
|
def send(self):
|
||||||
"""Queue the stanza to be sent on the XML stream.
|
"""Queue the stanza to be sent on the XML stream.
|
||||||
|
|
||||||
:param bool now: Indicates if the queue should be skipped and the
|
:param bool now: Indicates if the queue should be skipped and the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user