mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Cleaned basexmpp.py
This commit is contained in:
parent
d2aca3e7e0
commit
0d4d84b2fa
1 changed files with 68 additions and 28 deletions
|
@ -132,23 +132,35 @@ class BaseXMPP(XMLStream):
|
||||||
|
|
||||||
self.add_event_handler('disconnected',
|
self.add_event_handler('disconnected',
|
||||||
self._handle_disconnected)
|
self._handle_disconnected)
|
||||||
self.add_event_handler('presence_available', self._handle_available)
|
self.add_event_handler('presence_available',
|
||||||
self.add_event_handler('presence_dnd', self._handle_available)
|
self._handle_available)
|
||||||
self.add_event_handler('presence_xa', self._handle_available)
|
self.add_event_handler('presence_dnd',
|
||||||
self.add_event_handler('presence_chat', self._handle_available)
|
self._handle_available)
|
||||||
self.add_event_handler('presence_away', self._handle_available)
|
self.add_event_handler('presence_xa',
|
||||||
self.add_event_handler('presence_unavailable', self._handle_unavailable)
|
self._handle_available)
|
||||||
self.add_event_handler('presence_subscribe', self._handle_subscribe)
|
self.add_event_handler('presence_chat',
|
||||||
self.add_event_handler('presence_subscribed', self._handle_subscribed)
|
self._handle_available)
|
||||||
self.add_event_handler('presence_unsubscribe', self._handle_unsubscribe)
|
self.add_event_handler('presence_away',
|
||||||
self.add_event_handler('presence_unsubscribed', self._handle_unsubscribed)
|
self._handle_available)
|
||||||
self.add_event_handler('presence_probe', self._handle_probe)
|
self.add_event_handler('presence_unavailable',
|
||||||
self.add_event_handler('roster_subscription_request', self._handle_new_subscription)
|
self._handle_unavailable)
|
||||||
|
self.add_event_handler('presence_subscribe',
|
||||||
|
self._handle_subscribe)
|
||||||
|
self.add_event_handler('presence_subscribed',
|
||||||
|
self._handle_subscribed)
|
||||||
|
self.add_event_handler('presence_unsubscribe',
|
||||||
|
self._handle_unsubscribe)
|
||||||
|
self.add_event_handler('presence_unsubscribed',
|
||||||
|
self._handle_unsubscribed)
|
||||||
|
self.add_event_handler('presence_probe',
|
||||||
|
self._handle_probe)
|
||||||
|
self.add_event_handler('roster_subscription_request',
|
||||||
|
self._handle_new_subscription)
|
||||||
|
|
||||||
# Set up the XML stream with XMPP's root stanzas.
|
# Set up the XML stream with XMPP's root stanzas.
|
||||||
self.registerStanza(Message)
|
self.register_stanza(Message)
|
||||||
self.registerStanza(Iq)
|
self.register_stanza(Iq)
|
||||||
self.registerStanza(Presence)
|
self.register_stanza(Presence)
|
||||||
|
|
||||||
# Initialize a few default stanza plugins.
|
# Initialize a few default stanza plugins.
|
||||||
register_stanza_plugin(Iq, Roster)
|
register_stanza_plugin(Iq, Roster)
|
||||||
|
@ -536,12 +548,28 @@ class BaseXMPP(XMLStream):
|
||||||
self.event('message', msg)
|
self.event('message', msg)
|
||||||
|
|
||||||
def _handle_available(self, presence):
|
def _handle_available(self, presence):
|
||||||
self.roster[presence['to'].bare][presence['from'].bare].handle_available(presence)
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].handle_available(presence)
|
||||||
|
|
||||||
def _handle_unavailable(self, presence):
|
def _handle_unavailable(self, presence):
|
||||||
self.roster[presence['to'].bare][presence['from'].bare].handle_unavailable(presence)
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].handle_unavailable(presence)
|
||||||
|
|
||||||
def _handle_new_subscription(self, stanza):
|
def _handle_new_subscription(self, stanza):
|
||||||
|
"""
|
||||||
|
Attempt to automatically handle subscription requests.
|
||||||
|
|
||||||
|
Subscriptions will be approved if the request is from
|
||||||
|
a whitelisted JID, of self.auto_authorize is True. They
|
||||||
|
will be rejected if self.auto_authorize is False. Setting
|
||||||
|
self.auto_authorize to None will disable automatic
|
||||||
|
subscription handling (except for whitelisted JIDs).
|
||||||
|
|
||||||
|
If a subscription is accepted, a request for a mutual
|
||||||
|
subscription will be sent if self.auto_subscribe is True.
|
||||||
|
"""
|
||||||
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']:
|
||||||
|
@ -554,22 +582,34 @@ class BaseXMPP(XMLStream):
|
||||||
item.unauthorize()
|
item.unauthorize()
|
||||||
|
|
||||||
def _handle_removed_subscription(self, presence):
|
def _handle_removed_subscription(self, presence):
|
||||||
self.roster[presence['to'].bare][presence['from'].bare].unauthorize()
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].unauthorize()
|
||||||
|
|
||||||
def _handle_subscribe(self, stanza):
|
def _handle_subscribe(self, presence):
|
||||||
self.roster[stanza['to'].bare][stanza['from'].bare].handle_subscribe(stanza)
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].handle_subscribe(presence)
|
||||||
|
|
||||||
def _handle_subscribed(self, stanza):
|
def _handle_subscribed(self, presence):
|
||||||
self.roster[stanza['to'].bare][stanza['from'].bare].handle_subscribed(stanza)
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].handle_subscribed(presence)
|
||||||
|
|
||||||
def _handle_unsubscribe(self, stanza):
|
def _handle_unsubscribe(self, presence):
|
||||||
self.roster[stanza['to'].bare][stanza['from'].bare].handle_unsubscribe(stanza)
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].handle_unsubscribe(presence)
|
||||||
|
|
||||||
def _handle_unsubscribed(self, stanza):
|
def _handle_unsubscribed(self, presence):
|
||||||
self.roster[stanza['to'].bare][stanza['from'].bare].handle_unsubscribed(stanza)
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].handle_unsubscribed(presence)
|
||||||
|
|
||||||
def _handle_probe(self, stanza):
|
def _handle_probe(self, presence):
|
||||||
self.roster[stanza['to'].bare][stanza['from'].bare].handle_probe(stanza)
|
pto = presence['to'].bare
|
||||||
|
pfrom = presence['from'].bare
|
||||||
|
self.roster[pto][pfrom].handle_probe(presence)
|
||||||
|
|
||||||
def _handle_presence(self, presence):
|
def _handle_presence(self, presence):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue