changeset f8f59c1a8fac in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=f8f59c1a8fac
description: Push method to check if a specific ClientCaps supports a feature
down to the caps module.
Public interfaces stay the same.
diffstat:
src/common/caps.py | 27 ++++++++++++++++++++++++++-
src/common/contacts.py | 20 +++-----------------
test/unit/test_caps.py | 16 +++++++---------
3 files changed, 36 insertions(+), 27 deletions(-)
diffs (136 lines):
diff -r a1c66d95d5a4 -r f8f59c1a8fac src/common/caps.py
--- a/src/common/caps.py Thu Nov 05 22:16:38 2009 +0100
+++ b/src/common/caps.py Mon Nov 09 21:26:56 2009 +0100
@@ -41,12 +41,29 @@
FEATURE_BLACKLIST = [NS_CHATSTATES, NS_XHTML_IM, NS_RECEIPTS, NS_ESESSION]
+################################################################################
+### Public API of this module
+################################################################################
+
capscache = None
def initialize(logger):
- ''' Initializes the capscache global '''
+ ''' Initializes this module '''
global capscache
capscache = CapsCache(logger)
+def client_supports(client_caps, requested_feature):
+ lookup_item = client_caps.get_cache_lookup_strategy()
+ cache_item = lookup_item(capscache)
+
+ supported_features = cache_item.features
+ if requested_feature in supported_features:
+ return True
+ elif supported_features == [] and cache_item.queried in (0, 1):
+ # assume feature is supported, if we don't know yet, what the
client
+ # is capable of
+ return requested_feature not in FEATURE_BLACKLIST
+ else:
+ return False
def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'):
'''Compute caps hash according to XEP-0115, V1.5
@@ -118,6 +135,10 @@
return base64.b64encode(hash_.digest())
+################################################################################
+### Internal classes of this module
+################################################################################
+
class AbstractClientCaps(object):
'''
Base class representing a client and its capabilities as advertised by
@@ -323,6 +344,10 @@
discover(connection, jid)
+################################################################################
+### Caps network coding
+################################################################################
+
class ConnectionCaps(object):
'''
This class highly depends on that it is a part of Connection class.
diff -r a1c66d95d5a4 -r f8f59c1a8fac src/common/contacts.py
--- a/src/common/contacts.py Thu Nov 05 22:16:38 2009 +0100
+++ b/src/common/contacts.py Mon Nov 09 21:26:56 2009 +0100
@@ -29,7 +29,7 @@
##
import common.gajim
-from common import caps
+import caps
class XMPPEntity(object):
'''Base representation of entities in XMPP'''
@@ -72,7 +72,7 @@
def get_shown_name(self):
raise NotImplementedError
-
+
def supports(self, requested_feature):
'''
Returns True if the contact has advertised to support the
feature
@@ -85,21 +85,7 @@
# return caps for a contact that has no resources left.
return False
else:
- return self._client_supports(requested_feature)
-
- def _client_supports(self, requested_feature):
- lookup_item = self.client_caps.get_cache_lookup_strategy()
- cache_item = lookup_item(caps.capscache)
-
- supported_features = cache_item.features
- if requested_feature in supported_features:
- return True
- elif supported_features == [] and cache_item.queried in (0, 1):
- # assume feature is supported, if we don't know yet,
what the client
- # is capable of
- return requested_feature not in caps.FEATURE_BLACKLIST
- else:
- return False
+ return caps.client_supports(self.client_caps,
requested_feature)
class Contact(CommonContact):
diff -r a1c66d95d5a4 -r f8f59c1a8fac test/unit/test_caps.py
--- a/test/unit/test_caps.py Thu Nov 05 22:16:38 2009 +0100
+++ b/test/unit/test_caps.py Mon Nov 09 21:26:56 2009 +0100
@@ -113,25 +113,23 @@
"http://gajim.org#m3P2WeXPMGVH2tZPe7yITnfY0Dw=")
def test_client_supports(self):
- contact = Contact(jid=None, account=None,
client_caps=self.client_caps)
-
- self.assertTrue(contact.supports(NS_PING),
+ self.assertTrue(caps.client_supports(self.client_caps, NS_PING),
msg="Assume supported, if we don't have caps")
- self.assertFalse(contact.supports(NS_XHTML_IM),
+ self.assertFalse(caps.client_supports(self.client_caps,
NS_XHTML_IM),
msg="Must not assume blacklisted feature is supported
on default")
self.cc.initialize_from_db()
- self.assertFalse(contact.supports(NS_PING),
+ self.assertFalse(caps.client_supports(self.client_caps,
NS_PING),
msg="Must return false on unsupported feature")
- self.assertTrue(contact.supports(NS_XHTML_IM),
+ self.assertTrue(caps.client_supports(self.client_caps,
NS_XHTML_IM),
msg="Must return True on supported feature")
- self.assertTrue(contact.supports(NS_MUC),
- msg="Must return True on supported feature")
-
+ self.assertTrue(caps.client_supports(self.client_caps, NS_MUC),
+ msg="Must return True on supported feature")
+
class TestOldClientCaps(TestClientCaps):
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits