summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sleekxmpp/basexmpp.py27
-rw-r--r--sleekxmpp/clientxmpp.py2
-rw-r--r--sleekxmpp/roster.py35
-rw-r--r--sleekxmpp/test/sleektest.py2
-rw-r--r--tests/test_stanza_presence.py3
-rw-r--r--tests/test_stream_presence.py2
-rw-r--r--tests/test_stream_roster.py2
7 files changed, 36 insertions, 37 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py
index 23579fad..446871d3 100644
--- a/sleekxmpp/basexmpp.py
+++ b/sleekxmpp/basexmpp.py
@@ -15,7 +15,7 @@ import logging
import sleekxmpp
from sleekxmpp import plugins
-from sleekxmpp.roster import MultiRoster
+import sleekxmpp.roster as roster
from sleekxmpp.stanza import Message, Presence, Iq, Error
from sleekxmpp.stanza.roster import Roster
from sleekxmpp.stanza.nick import Nick
@@ -117,9 +117,8 @@ class BaseXMPP(XMLStream):
self.boundjid = JID(jid)
self.plugin = {}
- self.rosters = MultiRoster(self)
- self.rosters.add(self.boundjid.bare)
- self.roster = {}
+ self.roster = roster.Roster(self)
+ self.roster.add(self.boundjid.bare)
self.is_component = False
self.auto_authorize = True
@@ -543,15 +542,15 @@ class BaseXMPP(XMLStream):
self.event('message', msg)
def _handle_available(self, presence):
- self.rosters[presence['to'].bare][presence['from'].bare].handle_available(presence)
+ self.roster[presence['to'].bare][presence['from'].bare].handle_available(presence)
def _handle_unavailable(self, presence):
- self.rosters[presence['to'].bare][presence['from'].bare].handle_unavailable(presence)
+ self.roster[presence['to'].bare][presence['from'].bare].handle_unavailable(presence)
def _handle_new_subscription(self, stanza):
logging.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
- roster = self.rosters[stanza['to'].bare]
- item = self.rosters[stanza['to'].bare][stanza['from'].bare]
+ roster = self.roster[stanza['to'].bare]
+ item = self.roster[stanza['to'].bare][stanza['from'].bare]
if item['whitelisted']:
item.authorize()
elif roster.auto_authorize:
@@ -562,22 +561,22 @@ class BaseXMPP(XMLStream):
item.unauthorize()
def _handle_removed_subscription(self, presence):
- self.rosters[presence['to'].bare][presence['from'].bare].unauthorize()
+ self.roster[presence['to'].bare][presence['from'].bare].unauthorize()
def _handle_subscribe(self, stanza):
- self.rosters[stanza['to'].bare][stanza['from'].bare].handle_subscribe(stanza)
+ self.roster[stanza['to'].bare][stanza['from'].bare].handle_subscribe(stanza)
def _handle_subscribed(self, stanza):
- self.rosters[stanza['to'].bare][stanza['from'].bare].handle_subscribed(stanza)
+ self.roster[stanza['to'].bare][stanza['from'].bare].handle_subscribed(stanza)
def _handle_unsubscribe(self, stanza):
- self.rosters[stanza['to'].bare][stanza['from'].bare].handle_unsubscribe(stanza)
+ self.roster[stanza['to'].bare][stanza['from'].bare].handle_unsubscribe(stanza)
def _handle_unsubscribed(self, stanza):
- self.rosters[stanza['to'].bare][stanza['from'].bare].handle_unsubscribed(stanza)
+ self.roster[stanza['to'].bare][stanza['from'].bare].handle_unsubscribed(stanza)
def _handle_probe(self, stanza):
- self.rosteritems[stanza['to'].bare][stanza['from'].bare].handle_probe(stanza)
+ self.roster[stanza['to'].bare][stanza['from'].bare].handle_probe(stanza)
def _handle_presence(self, presence):
"""
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py
index 4bf759ea..376fcf89 100644
--- a/sleekxmpp/clientxmpp.py
+++ b/sleekxmpp/clientxmpp.py
@@ -418,7 +418,7 @@ class ClientXMPP(BaseXMPP):
if iq['type'] == 'set' or (iq['type'] == 'result' and request):
for jid in iq['roster']['items']:
item = iq['roster']['items'][jid]
- roster = self.rosters[iq['to'].bare]
+ roster = self.roster[iq['to'].bare]
roster[jid]['name'] = item['name']
roster[jid]['groups'] = item['groups']
roster[jid]['from'] = item['subscription'] in ['from', 'both']
diff --git a/sleekxmpp/roster.py b/sleekxmpp/roster.py
index 32fd5c0f..de96296b 100644
--- a/sleekxmpp/roster.py
+++ b/sleekxmpp/roster.py
@@ -1,11 +1,11 @@
import logging
-class MultiRoster(object):
+class Roster(object):
- def __init__(self, xmpp, datastore=None):
+ def __init__(self, xmpp, db=None):
self.xmpp = xmpp
- self.datastore = datastore
+ self.db = db
self._rosters = {}
def __getitem__(self, key):
@@ -21,14 +21,14 @@ class MultiRoster(object):
def add(self, node):
if node not in self._rosters:
- self._rosters[node] = Roster(self.xmpp, node, self.datastore)
+ self._rosters[node] = RosterNode(self.xmpp, node, self.db)
-class Roster(object):
+class RosterNode(object):
- def __init__(self, xmpp, jid, datastore=None):
+ def __init__(self, xmpp, jid, db=None):
self.xmpp = xmpp
self.jid = jid
- self.datastore = datastore
+ self.db = db
self.auto_authorize = True
self.auto_subscribe = True
self._jids = {}
@@ -56,7 +56,7 @@ class Roster(object):
'whitelisted': whitelisted,
'subscription': 'none'}
self._jids[jid] = RosterItem(self.xmpp, jid, self.jid,
- state=state, datastore=self.datastore)
+ state=state, db=self.db)
if save:
self._jids[jid].save()
@@ -99,14 +99,13 @@ class Roster(object):
class RosterItem(object):
def __init__(self, xmpp, jid, owner=None,
- state=None, datastore=None):
+ state=None, db=None):
self.xmpp = xmpp
self.jid = jid
self.owner = owner or self.xmpp.jid
self.last_status = None
self.resources = {}
- self.datastore = datastore
-
+ self.db = db
self._state = state or {
'from': False,
'to': False,
@@ -116,13 +115,13 @@ class RosterItem(object):
'subscription': 'none',
'name': '',
'groups': []}
- self._datastore_state = {}
+ self._db_state = {}
self.load()
def load(self):
- if self.datastore:
- item = self.datastore.load(self.owner, self.jid,
- self._datastore_state)
+ if self.db:
+ item = self.db.load(self.owner, self.jid,
+ self._db_state)
if item:
self['name'] = item['name']
self['groups'] = item['groups']
@@ -136,9 +135,9 @@ class RosterItem(object):
return None
def save(self):
- if self.datastore:
- self.datastore.save(self.owner, self.jid,
- self._state, self._datastore_state)
+ if self.db:
+ self.db.save(self.owner, self.jid,
+ self._state, self._db_state)
def __getitem__(self, key):
if key in self._state:
diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py
index cf38e78f..4cc913a0 100644
--- a/sleekxmpp/test/sleektest.py
+++ b/sleekxmpp/test/sleektest.py
@@ -141,7 +141,7 @@ class SleekTest(unittest.TestCase):
def check_roster(self, owner, jid, name=None, subscription=None,
afrom=None, ato=None, pending_out=None, pending_in=None,
groups=None):
- roster = self.xmpp.rosters[owner][jid]
+ roster = self.xmpp.roster[owner][jid]
print roster._state
if name is not None:
self.assertEqual(roster['name'], name,
diff --git a/tests/test_stanza_presence.py b/tests/test_stanza_presence.py
index 6a5a8b6e..1a7d44da 100644
--- a/tests/test_stanza_presence.py
+++ b/tests/test_stanza_presence.py
@@ -49,7 +49,8 @@ class TestPresenceStanzas(SleekTest):
self.failUnless(happened == [],
"changed_status event triggered for extra unavailable presence")
- self.failUnless(c.roster == {},
+ roster = c.roster['crap@wherever']
+ self.failUnless(roster['bill@chadmore.com'].resources == {},
"Roster updated for superfulous unavailable presence")
def testNickPlugin(self):
diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py
index c873799a..b259495e 100644
--- a/tests/test_stream_presence.py
+++ b/tests/test_stream_presence.py
@@ -183,7 +183,7 @@ class TestStreamPresence(SleekTest):
presence_subscribe)
# With this setting we should reject all subscriptions.
- self.xmpp.rosters['tester@localhost'].auto_authorize = False
+ self.xmpp.roster['tester@localhost'].auto_authorize = False
self.stream_recv("""
<presence from="user@localhost"
diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py
index 67da6e6c..f5617fb6 100644
--- a/tests/test_stream_roster.py
+++ b/tests/test_stream_roster.py
@@ -41,7 +41,7 @@ class TestStreamRoster(SleekTest):
# Wait for get_roster to return.
t.join()
- print self.xmpp.rosters['tester@localhost']['user@localhost']._state
+ print self.xmpp.roster['tester@localhost']['user@localhost']._state
self.check_roster('tester@localhost', 'user@localhost',
name='User',
subscription='from',