diff options
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/basexmpp.py | 27 | ||||
-rw-r--r-- | sleekxmpp/clientxmpp.py | 2 | ||||
-rw-r--r-- | sleekxmpp/roster.py | 35 | ||||
-rw-r--r-- | sleekxmpp/test/sleektest.py | 2 |
4 files changed, 32 insertions, 34 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, |