XEP-0092: Add type hints and switch to default args

This commit is contained in:
mathieui 2021-02-04 21:26:20 +01:00
parent 8e612bf229
commit 99c2e5cafd

View File

@ -8,8 +8,12 @@
import logging import logging
from asyncio import Future
from typing import Optional
import slixmpp import slixmpp
from slixmpp import Iq from slixmpp import JID
from slixmpp.stanza import Iq
from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath from slixmpp.xmlstream.matcher import StanzaPath
@ -57,12 +61,11 @@ class XEP_0092(BasePlugin):
def session_bind(self, jid): def session_bind(self, jid):
self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:version') self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:version')
def _handle_version(self, iq): def _handle_version(self, iq: Iq):
""" """
Respond to a software version query. Respond to a software version query.
Arguments: :param iq: The Iq stanza containing the software version query.
iq -- The Iq stanza containing the software version query.
""" """
iq = iq.reply() iq = iq.reply()
if self.software_name: if self.software_name:
@ -75,18 +78,12 @@ class XEP_0092(BasePlugin):
iq['error']['condition'] = 'service-unavailable' iq['error']['condition'] = 'service-unavailable'
iq.send() iq.send()
def get_version(self, jid, ifrom=None, timeout=None, callback=None, def get_version(self, jid: JID, ifrom: Optional[JID] = None, **iqkwargs) -> Future:
timeout_callback=None):
""" """
Retrieve the software version of a remote agent. Retrieve the software version of a remote agent.
Arguments: :param jid: The JID of the entity to query.
jid -- The JID of the entity to query.
""" """
iq = self.xmpp.Iq() iq = self.xmpp.make_iq_get(ito=jid, ifrom=ifrom)
iq['to'] = jid
iq['from'] = ifrom
iq['type'] = 'get'
iq['query'] = Version.namespace iq['query'] = Version.namespace
return iq.send(timeout=timeout, callback=callback, return iq.send(**iqkwargs)
timeout_callback=timeout_callback)