2011-03-23 00:42:43 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
|
|
|
See the file LICENSE for copying permission.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import sleekxmpp
|
|
|
|
from sleekxmpp.plugins.xep_0030 import StaticDisco
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class StaticExtendedDisco(object):
|
|
|
|
|
|
|
|
"""
|
|
|
|
Extend the default StaticDisco implementation to provide
|
|
|
|
support for extended identity information.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, static):
|
|
|
|
"""
|
|
|
|
Augment the default XEP-0030 static handler object.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
static -- The default static XEP-0030 handler object.
|
|
|
|
"""
|
|
|
|
self.static = static
|
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def set_extended_info(self, jid, node, ifrom, data):
|
2011-03-23 00:42:43 +00:00
|
|
|
"""
|
|
|
|
Replace the extended identity data for a JID/node combination.
|
|
|
|
|
|
|
|
The data parameter may provide:
|
|
|
|
data -- Either a single data form, or a list of data forms.
|
|
|
|
"""
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
with self.static.lock:
|
|
|
|
self.del_extended_info(jid, node, ifrom, data)
|
|
|
|
self.add_extended_info(jid, node, ifrom, data)
|
2011-03-23 00:42:43 +00:00
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def add_extended_info(self, jid, node, ifrom, data):
|
2011-03-23 00:42:43 +00:00
|
|
|
"""
|
|
|
|
Add additional extended identity data for a JID/node combination.
|
|
|
|
|
|
|
|
The data parameter may provide:
|
|
|
|
data -- Either a single data form, or a list of data forms.
|
|
|
|
"""
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
with self.static.lock:
|
|
|
|
self.static.add_node(jid, node)
|
2011-03-23 00:42:43 +00:00
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
forms = data.get('data', [])
|
|
|
|
if not isinstance(forms, list):
|
|
|
|
forms = [forms]
|
2011-03-23 00:42:43 +00:00
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
info = self.static.get_node(jid, node)['info']
|
|
|
|
for form in forms:
|
|
|
|
info.append(form)
|
2011-03-23 00:42:43 +00:00
|
|
|
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
def del_extended_info(self, jid, node, ifrom, data):
|
2011-03-23 00:42:43 +00:00
|
|
|
"""
|
|
|
|
Replace the extended identity data for a JID/node combination.
|
|
|
|
|
|
|
|
The data parameter is not used.
|
|
|
|
"""
|
Add caching support to xep_0030.
New plugin configuration options:
use_cache - Enable caching disco info results. Defaults to True
wrap_results - Always return disco results in an Iq stanza. Defaults
to False
Node handler changes:
Handlers now take four arguments: jid, node, ifrom, data
Most older style handlers will still work, depending on if they
raise a TypeError for incorrect number of arguments. Handlers that
used *args may not work.
New get_info options:
cached - Passing cached=True to get_info() will attempt to load
results from the cache. If nothing is found, a query
will be sent as normal. If set to False, the cache
will be skipped, even if it contains results.
New method:
supports() - Given a JID/node pair and a feature, return True
if the feature is supported, False if not, and
None if there was a timeout. By default, the search
will use the cache.
2011-12-28 15:07:33 +00:00
|
|
|
with self.static.lock:
|
|
|
|
if self.static.node_exists(jid, node):
|
|
|
|
info = self.static.get_node(jid, node)['info']
|
|
|
|
for form in info['substanza']:
|
|
|
|
info.xml.remove(form.xml)
|