mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-24 03:00:15 +00:00
More cleanup.
This commit is contained in:
parent
c2c18acd6a
commit
4f69a03bb1
2 changed files with 40 additions and 4 deletions
|
@ -548,7 +548,6 @@ class BaseXMPP(XMLStream):
|
||||||
self.roster[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):
|
def _handle_new_subscription(self, stanza):
|
||||||
logging.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
|
|
||||||
roster = self.roster[stanza['to'].bare]
|
roster = self.roster[stanza['to'].bare]
|
||||||
item = self.roster[stanza['to'].bare][stanza['from'].bare]
|
item = self.roster[stanza['to'].bare][stanza['from'].bare]
|
||||||
if item['whitelisted']:
|
if item['whitelisted']:
|
||||||
|
|
|
@ -364,9 +364,20 @@ class RosterItem(object):
|
||||||
|
|
||||||
def __init__(self, xmpp, jid, owner=None,
|
def __init__(self, xmpp, jid, owner=None,
|
||||||
state=None, db=None):
|
state=None, db=None):
|
||||||
|
"""
|
||||||
|
Create a new roster item.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
xmpp -- The main SleekXMPP instance.
|
||||||
|
jid -- The item's JID.
|
||||||
|
owner -- The roster owner's JID. Defaults
|
||||||
|
so self.xmpp.boundjid.bare.
|
||||||
|
state -- A dictionary of initial state values.
|
||||||
|
db -- An optional interface to an external datastore.
|
||||||
|
"""
|
||||||
self.xmpp = xmpp
|
self.xmpp = xmpp
|
||||||
self.jid = jid
|
self.jid = jid
|
||||||
self.owner = owner or self.xmpp.jid
|
self.owner = owner or self.xmpp.boundjid.bare
|
||||||
self.last_status = None
|
self.last_status = None
|
||||||
self.resources = {}
|
self.resources = {}
|
||||||
self.db = db
|
self.db = db
|
||||||
|
@ -383,6 +394,10 @@ class RosterItem(object):
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
"""
|
||||||
|
Load the item's state information from an external datastore,
|
||||||
|
if one has been provided.
|
||||||
|
"""
|
||||||
if self.db:
|
if self.db:
|
||||||
item = self.db.load(self.owner, self.jid,
|
item = self.db.load(self.owner, self.jid,
|
||||||
self._db_state)
|
self._db_state)
|
||||||
|
@ -399,11 +414,16 @@ class RosterItem(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
"""
|
||||||
|
Save the item's state information to an external datastore,
|
||||||
|
if one has been provided.
|
||||||
|
"""
|
||||||
if self.db:
|
if self.db:
|
||||||
self.db.save(self.owner, self.jid,
|
self.db.save(self.owner, self.jid,
|
||||||
self._state, self._db_state)
|
self._state, self._db_state)
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
|
"""Return a state field's value."""
|
||||||
if key in self._state:
|
if key in self._state:
|
||||||
if key == 'subscription':
|
if key == 'subscription':
|
||||||
return self._subscription()
|
return self._subscription()
|
||||||
|
@ -412,6 +432,16 @@ class RosterItem(object):
|
||||||
raise KeyError
|
raise KeyError
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
|
"""
|
||||||
|
Set the value of a state field.
|
||||||
|
|
||||||
|
For boolean states, the values True, 'true', '1', 'on',
|
||||||
|
and 'yes' are accepted as True; all others are False.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
key -- The state field to modify.
|
||||||
|
value -- The new value of the state field.
|
||||||
|
"""
|
||||||
print "%s: %s" % (key, value)
|
print "%s: %s" % (key, value)
|
||||||
if key in self._state:
|
if key in self._state:
|
||||||
if key in ['name', 'subscription', 'groups']:
|
if key in ['name', 'subscription', 'groups']:
|
||||||
|
@ -423,6 +453,7 @@ class RosterItem(object):
|
||||||
raise KeyError
|
raise KeyError
|
||||||
|
|
||||||
def _subscription(self):
|
def _subscription(self):
|
||||||
|
"""Return the proper subscription type based on current state."""
|
||||||
if self['to'] and self['from']:
|
if self['to'] and self['from']:
|
||||||
return 'both'
|
return 'both'
|
||||||
elif self['from']:
|
elif self['from']:
|
||||||
|
@ -434,8 +465,8 @@ class RosterItem(object):
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
"""
|
"""
|
||||||
Remove the jids subscription, inform it if it is
|
Remove a JID's whitelisted status and unsubscribe if a
|
||||||
subscribed, and unwhitelist it.
|
subscription exists.
|
||||||
"""
|
"""
|
||||||
if self['to']:
|
if self['to']:
|
||||||
p = self.xmpp.Presence()
|
p = self.xmpp.Presence()
|
||||||
|
@ -449,6 +480,7 @@ class RosterItem(object):
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def subscribe(self):
|
def subscribe(self):
|
||||||
|
"""Send a subscription request to the JID."""
|
||||||
p = self.xmpp.Presence()
|
p = self.xmpp.Presence()
|
||||||
p['to'] = self.jid
|
p['to'] = self.jid
|
||||||
p['type'] = 'subscribe'
|
p['type'] = 'subscribe'
|
||||||
|
@ -459,6 +491,7 @@ class RosterItem(object):
|
||||||
p.send()
|
p.send()
|
||||||
|
|
||||||
def authorize(self):
|
def authorize(self):
|
||||||
|
"""Authorize a received subscription request from the JID."""
|
||||||
self['from'] = True
|
self['from'] = True
|
||||||
self['pending_in'] = False
|
self['pending_in'] = False
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -466,6 +499,7 @@ class RosterItem(object):
|
||||||
self.send_last_presence()
|
self.send_last_presence()
|
||||||
|
|
||||||
def unauthorize(self):
|
def unauthorize(self):
|
||||||
|
"""Deny a received subscription request from the JID."""
|
||||||
self['from'] = False
|
self['from'] = False
|
||||||
self['pending_in'] = False
|
self['pending_in'] = False
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -478,6 +512,7 @@ class RosterItem(object):
|
||||||
p.send()
|
p.send()
|
||||||
|
|
||||||
def _subscribed(self):
|
def _subscribed(self):
|
||||||
|
"""Handle acknowledging a subscription."""
|
||||||
p = self.xmpp.Presence()
|
p = self.xmpp.Presence()
|
||||||
p['to'] = self.jid
|
p['to'] = self.jid
|
||||||
p['type'] = 'subscribed'
|
p['type'] = 'subscribed'
|
||||||
|
@ -486,6 +521,7 @@ class RosterItem(object):
|
||||||
p.send()
|
p.send()
|
||||||
|
|
||||||
def unsubscribe(self):
|
def unsubscribe(self):
|
||||||
|
"""Unsubscribe from the JID."""
|
||||||
p = self.xmpp.Presence()
|
p = self.xmpp.Presence()
|
||||||
p['to'] = self.jid
|
p['to'] = self.jid
|
||||||
p['type'] = 'unsubscribe'
|
p['type'] = 'unsubscribe'
|
||||||
|
@ -495,6 +531,7 @@ class RosterItem(object):
|
||||||
p.send()
|
p.send()
|
||||||
|
|
||||||
def _unsubscribed(self):
|
def _unsubscribed(self):
|
||||||
|
"""Handle acknowledging an unsubscribe request."""
|
||||||
p = self.xmpp.Presence()
|
p = self.xmpp.Presence()
|
||||||
p['to'] = self.jid
|
p['to'] = self.jid
|
||||||
p['type'] = 'unsubscribed'
|
p['type'] = 'unsubscribed'
|
||||||
|
|
Loading…
Reference in a new issue