summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-10-27 08:09:50 -0400
committerLance Stout <lancestout@gmail.com>2010-11-17 01:49:51 -0500
commit69d430dd75f526984fd6ea6f9db294731698712c (patch)
treeb3e6a1eec56cde1633486cc91cf92bc2362b587c
parent673545c7e48d86b02f811ad239ed317e4bca0bbc (diff)
downloadslixmpp-69d430dd75f526984fd6ea6f9db294731698712c.tar.gz
slixmpp-69d430dd75f526984fd6ea6f9db294731698712c.tar.bz2
slixmpp-69d430dd75f526984fd6ea6f9db294731698712c.tar.xz
slixmpp-69d430dd75f526984fd6ea6f9db294731698712c.zip
Cleaned up names.
-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 fb718fba..46c8985a 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
@@ -111,9 +111,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
@@ -537,14 +536,14 @@ 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):
- 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:
@@ -555,22 +554,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 8b8f05f6..dbf87647 100644
--- a/sleekxmpp/clientxmpp.py
+++ b/sleekxmpp/clientxmpp.py
@@ -421,7 +421,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 c481d73b..0b6664b5 100644
--- a/sleekxmpp/test/sleektest.py
+++ b/sleekxmpp/test/sleektest.py
@@ -140,7 +140,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 8d043d5d..b8600b6a 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 8ca1c0e9..3e0933d7 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.recv("""
<presence from="user@localhost"
diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py
index 8ffd86aa..7edaecd1 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',