mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-12-28 11:14:19 +00:00
Cleaned up names.
This commit is contained in:
parent
65aa6573df
commit
c6ed4b8a1d
7 changed files with 36 additions and 37 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue