summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0030
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-12-30 20:53:18 -0500
committerLance Stout <lancestout@gmail.com>2011-12-30 20:53:18 -0500
commit8eb225bdecd33e85b5b0e6c447f0ae4eee47201f (patch)
tree833253ddb4e86cb8c0c7c517829a11b6a8b4aa4c /sleekxmpp/plugins/xep_0030
parenta7df76a275e0e68176008cd6ae3a5ca2955667b2 (diff)
downloadslixmpp-8eb225bdecd33e85b5b0e6c447f0ae4eee47201f.tar.gz
slixmpp-8eb225bdecd33e85b5b0e6c447f0ae4eee47201f.tar.bz2
slixmpp-8eb225bdecd33e85b5b0e6c447f0ae4eee47201f.tar.xz
slixmpp-8eb225bdecd33e85b5b0e6c447f0ae4eee47201f.zip
Add option for disabling identity and feature deduplication.
XEP-0115 requires detecting duplicates, so we can't always silently ignore them.
Diffstat (limited to 'sleekxmpp/plugins/xep_0030')
-rw-r--r--sleekxmpp/plugins/xep_0030/stanza/info.py36
1 files changed, 25 insertions, 11 deletions
diff --git a/sleekxmpp/plugins/xep_0030/stanza/info.py b/sleekxmpp/plugins/xep_0030/stanza/info.py
index 6764acbb..25d1d07f 100644
--- a/sleekxmpp/plugins/xep_0030/stanza/info.py
+++ b/sleekxmpp/plugins/xep_0030/stanza/info.py
@@ -146,7 +146,7 @@ class DiscoInfo(ElementBase):
return True
return False
- def get_identities(self, lang=None):
+ def get_identities(self, lang=None, dedupe=True):
"""
Return a set of all identities in tuple form as so:
(category, type, lang, name)
@@ -155,17 +155,25 @@ class DiscoInfo(ElementBase):
that language.
Arguments:
- lang -- Optional, standard xml:lang value.
+ lang -- Optional, standard xml:lang value.
+ dedupe -- If True, de-duplicate identities, otherwise
+ return a list of all identities.
"""
- identities = set()
+ if dedupe:
+ identities = set()
+ else:
+ identities = []
for id_xml in self.findall('{%s}identity' % self.namespace):
xml_lang = id_xml.attrib.get('{%s}lang' % self.xml_ns, None)
if lang is None or xml_lang == lang:
- identities.add((
- id_xml.attrib['category'],
- id_xml.attrib['type'],
- id_xml.attrib.get('{%s}lang' % self.xml_ns, None),
- id_xml.attrib.get('name', None)))
+ id = (id_xml.attrib['category'],
+ id_xml.attrib['type'],
+ id_xml.attrib.get('{%s}lang' % self.xml_ns, None),
+ id_xml.attrib.get('name', None))
+ if dedupe:
+ identities.add(id)
+ else:
+ identities.append(id)
return identities
def set_identities(self, identities, lang=None):
@@ -237,11 +245,17 @@ class DiscoInfo(ElementBase):
return True
return False
- def get_features(self):
+ def get_features(self, dedupe=True):
"""Return the set of all supported features."""
- features = set()
+ if dedupe:
+ features = set()
+ else:
+ features = []
for feature_xml in self.findall('{%s}feature' % self.namespace):
- features.add(feature_xml.attrib['var'])
+ if dedupe:
+ features.add(feature_xml.attrib['var'])
+ else:
+ features.append(feature_xml.attrib['var'])
return features
def set_features(self, features):