summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0054
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-02-05 20:14:41 +0100
committermathieui <mathieui@mathieui.net>2021-02-05 20:14:41 +0100
commitcff4588499d74e392cab646a46217f069cb1ef01 (patch)
treee349f9d4b1f13b57d4df820b8f649c8deee2a726 /slixmpp/plugins/xep_0054
parentc82e1a4039dbf5d24990d28d665ba973fc9c9de7 (diff)
parent89601289fea2c6f2b47002926eb2609bd72d2a17 (diff)
downloadslixmpp-cff4588499d74e392cab646a46217f069cb1ef01.tar.gz
slixmpp-cff4588499d74e392cab646a46217f069cb1ef01.tar.bz2
slixmpp-cff4588499d74e392cab646a46217f069cb1ef01.tar.xz
slixmpp-cff4588499d74e392cab646a46217f069cb1ef01.zip
Merge branch 'updat-typing-and-generic-args' into 'master'
Update typing and generic args for plugins (step 1) See merge request poezio/slixmpp!120
Diffstat (limited to 'slixmpp/plugins/xep_0054')
-rw-r--r--slixmpp/plugins/xep_0054/vcard_temp.py50
1 files changed, 30 insertions, 20 deletions
diff --git a/slixmpp/plugins/xep_0054/vcard_temp.py b/slixmpp/plugins/xep_0054/vcard_temp.py
index 214746e9..12840052 100644
--- a/slixmpp/plugins/xep_0054/vcard_temp.py
+++ b/slixmpp/plugins/xep_0054/vcard_temp.py
@@ -7,8 +7,11 @@
"""
import logging
+from asyncio import Future
+from typing import Optional
-from slixmpp import JID, Iq
+from slixmpp import JID
+from slixmpp.stanza import Iq
from slixmpp.exceptions import XMPPError
from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.xmlstream.handler import Callback
@@ -57,12 +60,22 @@ class XEP_0054(BasePlugin):
def session_bind(self, jid):
self.xmpp['xep_0030'].add_feature('vcard-temp')
- def make_vcard(self):
+ def make_vcard(self) -> VCardTemp:
+ """Return an empty vcard element."""
return VCardTemp()
@future_wrapper
- def get_vcard(self, jid=None, ifrom=None, local=None, cached=False,
- callback=None, timeout=None, timeout_callback=None):
+ def get_vcard(self, jid: Optional[JID] = None, *,
+ local: Optional[bool] = None, cached: bool = False,
+ ifrom: Optional[JID] = None,
+ **iqkwargs) -> Future:
+ """Retrieve a VCard.
+
+ :param jid: JID of the entity to fetch the VCard from.
+ :param local: Only check internally for a vcard.
+ :param cached: Whether to check in the local cache before
+ sending a query.
+ """
if local is None:
if jid is not None and not isinstance(jid, JID):
jid = JID(jid)
@@ -95,31 +108,28 @@ class XEP_0054(BasePlugin):
return iq
return vcard
- iq = self.xmpp.Iq()
- iq['to'] = jid
- iq['from'] = ifrom
- iq['type'] = 'get'
+ iq = self.xmpp.make_iq_get(ito=jid, ifrom=ifrom)
iq.enable('vcard_temp')
-
- return iq.send(callback=callback, timeout=timeout,
- timeout_callback=timeout_callback)
+ return iq.send(**iqkwargs)
@future_wrapper
- def publish_vcard(self, vcard=None, jid=None, ifrom=None,
- callback=None, timeout=None, timeout_callback=None):
+ def publish_vcard(self, vcard: Optional[VCardTemp] = None,
+ jid: Optional[JID] = None,
+ ifrom: Optional[JID] = None, **iqkwargs) -> Future:
+ """Publish a vcard.
+
+ :param vcard: The VCard to publish.
+ :param jid: The JID to publish the VCard to.
+ """
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 = self.xmpp.make_iq_set(ito=jid, ifrom=ifrom)
iq.append(vcard)
- return iq.send(callback=callback, timeout=timeout,
- timeout_callback=timeout_callback)
+ return iq.send(**iqkwargs)
- def _handle_get_vcard(self, iq):
+ def _handle_get_vcard(self, iq: Iq):
if iq['type'] == 'result':
self.api['set_vcard'](jid=iq['from'], args=iq['vcard_temp'])
return