
In a single commit, because it isn’t that interesting to detail each change. List of reverts: Revert "XEP-0030: allow get_info and get_items to return a coroutine" This reverts commit 506ca6991790cffb90c5b6e3b765237ccc136e1a. Revert "XEP-0060: wrap all iq-sending functions with coroutine_wrapper" This reverts commit e85fa4203e0ee7108d8d37f73913c21628e3d6fc. Revert "XEP-0163: wrap publish() with coroutine_wrapper" This reverts commit 69da1c1d7cf7a1c0dbbeeb83f528b4e5f5b5be0c. Revert "XEP-0084: wrap functions with coroutine_wrapper" This reverts commit ea5615f236bd80fb4217398977833ca790cbef71. Partially revert 3d243f7 (XEP-0054) - continue wrapping functions but with future_wrapper Partially revert 115fe95 (xep-0153) - use callbacks rather than coroutine callbacks, and propagate iqtimeouts in set_avatar. Revert "XEP-0049: wrap functions with coroutine_wrapper" This reverts commit e68135f59f9a224688679eb91e8063041d6f000b. Revert "XEP-0077: wrap functions with coroutine_wrapper" This reverts commit 1e4944d47e8296fdaa792a8b3fc87ea99acc217c. Partially revert cd7ff685 (XEP-0199) - remove the iq.send wrapping but keep ping() as a coroutine Revert "XEP-0257: wrap functions with coroutine_wrapper" This reverts commit 4da870fd191697d010e677eee32ef86439967353. Revert "XEP-0092: wrap get_version() with coroutine_wrapper" This reverts commit 6e35948276c36ea2696f0de64dc179a1073ee3a6. Revert "XEP-0191: wrap functions with coroutine_wrapper" This reverts commit 6e8235544cc1bdefea75a8d93e5e3a48a13552ba. Revert "XEP-0280: wrap functions with coroutine_wrapper" This reverts commit f795ac02e322445be13077463638924d1f22d313. Revert "XEP-0012: wrap get_last_activity() with coroutine_wrapper" This reverts commit 2ee05d9616d2959d19a7a87d21c58e6aae1db56e. Revert "XEP-0202: wrap get_entity_time() with coroutine_wrapper" This reverts commit 6fb3ecd414f24374f17811d7ad2fd01e4924e311. Revert "XEP-0231: wrap get_bob() with coroutine_wrapper" This reverts commit 17464b10a42d9b3c4daba763e06e53c429478abd. Revert "XEP-0258: wrap get_catalog() with coroutine_wrapper" This reverts commit 18a4978456a33e6ea38de1e07b1aa43bcc10d45f. Revert "XEP-0050: wrap send_command() and get_commands() with coroutine_wrapper" This reverts commit e034b31d6bc34f43578456e9c6527bc56dff78e3. Revert "XEP-0279: wrap check_ip() with coroutine_wrapper" This reverts commit e112e864756f1222a044ee28e3c13c5925618b0c.
146 lines
4.3 KiB
Python
146 lines
4.3 KiB
Python
"""
|
|
Slixmpp: The Slick XMPP Library
|
|
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
|
This file is part of Slixmpp.
|
|
|
|
See the file LICENSE for copying permission.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from slixmpp import JID, Iq
|
|
from slixmpp.exceptions import XMPPError
|
|
from slixmpp.xmlstream import register_stanza_plugin
|
|
from slixmpp.xmlstream.handler import Callback
|
|
from slixmpp.xmlstream.matcher import StanzaPath
|
|
from slixmpp.plugins import BasePlugin
|
|
from slixmpp.plugins.xep_0054 import VCardTemp, stanza
|
|
from slixmpp import future_wrapper
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class XEP_0054(BasePlugin):
|
|
|
|
"""
|
|
XEP-0054: vcard-temp
|
|
"""
|
|
|
|
name = 'xep_0054'
|
|
description = 'XEP-0054: vcard-temp'
|
|
dependencies = set(['xep_0030', 'xep_0082'])
|
|
stanza = stanza
|
|
|
|
def plugin_init(self):
|
|
"""
|
|
Start the XEP-0054 plugin.
|
|
"""
|
|
register_stanza_plugin(Iq, VCardTemp)
|
|
|
|
|
|
self.api.register(self._set_vcard, 'set_vcard', default=True)
|
|
self.api.register(self._get_vcard, 'get_vcard', default=True)
|
|
self.api.register(self._del_vcard, 'del_vcard', default=True)
|
|
|
|
self._vcard_cache = {}
|
|
|
|
self.xmpp.register_handler(
|
|
Callback('VCardTemp',
|
|
StanzaPath('iq/vcard_temp'),
|
|
self._handle_get_vcard))
|
|
|
|
def plugin_end(self):
|
|
self.xmpp.remove_handler('VCardTemp')
|
|
self.xmpp['xep_0030'].del_feature(feature='vcard-temp')
|
|
|
|
def session_bind(self, jid):
|
|
self.xmpp['xep_0030'].add_feature('vcard-temp')
|
|
|
|
def make_vcard(self):
|
|
return VCardTemp()
|
|
|
|
@future_wrapper
|
|
def get_vcard(self, jid=None, ifrom=None, local=None, cached=False,
|
|
callback=None, timeout=None):
|
|
if local is None:
|
|
if jid is not None and not isinstance(jid, JID):
|
|
jid = JID(jid)
|
|
if self.xmpp.is_component:
|
|
if jid.domain == self.xmpp.boundjid.domain:
|
|
local = True
|
|
else:
|
|
if str(jid) == str(self.xmpp.boundjid):
|
|
local = True
|
|
jid = jid.full
|
|
elif jid in (None, ''):
|
|
local = True
|
|
|
|
if local:
|
|
vcard = self.api['get_vcard'](jid, None, ifrom)
|
|
if not isinstance(vcard, Iq):
|
|
iq = self.xmpp.Iq()
|
|
if vcard is None:
|
|
vcard = VCardTemp()
|
|
iq.append(vcard)
|
|
return iq
|
|
return vcard
|
|
|
|
if cached:
|
|
vcard = self.api['get_vcard'](jid, None, ifrom)
|
|
if vcard is not None:
|
|
if not isinstance(vcard, Iq):
|
|
iq = self.xmpp.Iq()
|
|
iq.append(vcard)
|
|
return iq
|
|
return vcard
|
|
|
|
iq = self.xmpp.Iq()
|
|
iq['to'] = jid
|
|
iq['from'] = ifrom
|
|
iq['type'] = 'get'
|
|
iq.enable('vcard_temp')
|
|
|
|
return iq.send(callback=callback, timeout=timeout)
|
|
|
|
@future_wrapper
|
|
def publish_vcard(self, vcard=None, jid=None, ifrom=None,
|
|
callback=None, timeout=None):
|
|
self.api['set_vcard'](jid, None, ifrom, vcard)
|
|
if self.xmpp.is_component:
|
|
return
|
|
|
|
iq = self.xmpp.Iq()
|
|
iq['to'] = jid
|
|
iq['from'] = ifrom
|
|
iq['type'] = 'set'
|
|
iq.append(vcard)
|
|
return iq.send(callback=callback, timeout=timeout)
|
|
|
|
def _handle_get_vcard(self, iq):
|
|
if iq['type'] == 'result':
|
|
self.api['set_vcard'](jid=iq['from'], args=iq['vcard_temp'])
|
|
return
|
|
elif iq['type'] == 'get':
|
|
vcard = self.api['get_vcard'](iq['from'].bare)
|
|
if isinstance(vcard, Iq):
|
|
vcard.send()
|
|
else:
|
|
iq = iq.reply()
|
|
iq.append(vcard)
|
|
iq.send()
|
|
elif iq['type'] == 'set':
|
|
raise XMPPError('service-unavailable')
|
|
|
|
# =================================================================
|
|
|
|
def _set_vcard(self, jid, node, ifrom, vcard):
|
|
self._vcard_cache[jid.bare] = vcard
|
|
|
|
def _get_vcard(self, jid, node, ifrom, vcard):
|
|
return self._vcard_cache.get(jid.bare, None)
|
|
|
|
def _del_vcard(self, jid, node, ifrom, vcard):
|
|
if jid.bare in self._vcard_cache:
|
|
del self._vcard_cache[jid.bare]
|