From 712ac671e14b563375d43607e11d8007e10e05c3 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 4 Feb 2021 21:28:18 +0100 Subject: [PATCH] XEP-0152: Add type hints and switch to default args --- slixmpp/plugins/xep_0152/reachability.py | 37 +++++++++--------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/slixmpp/plugins/xep_0152/reachability.py b/slixmpp/plugins/xep_0152/reachability.py index 0ca0ae68..3c1a23aa 100644 --- a/slixmpp/plugins/xep_0152/reachability.py +++ b/slixmpp/plugins/xep_0152/reachability.py @@ -8,6 +8,8 @@ import logging +from asyncio import Future + from slixmpp import JID from typing import Dict, List, Optional, Callable from slixmpp.plugins.base import BasePlugin @@ -37,17 +39,12 @@ class XEP_0152(BasePlugin): self.xmpp['xep_0163'].register_pep('reachability', Reachability) def publish_reachability(self, addresses: List[Dict[str, str]], - options: Optional[Form] = None, - ifrom: Optional[JID] = None, - callback: Optional[Callable] = None, - timeout: Optional[int] = None, - timeout_callback: Optional[Callable] = None): + **pubsubkwargs) -> Future: """ Publish alternative addresses where the user can be reached. :param addresses: A list of dictionaries containing the URI and optional description for each address. - :param options: Optional form of publish options. """ if not isinstance(addresses, (list, tuple)): addresses = [addresses] @@ -60,25 +57,19 @@ class XEP_0152(BasePlugin): for key, val in address.items(): addr[key] = val reach.append(addr) - return self.xmpp['xep_0163'].publish(reach, - node=Reachability.namespace, - options=options, - ifrom=ifrom, - callback=callback, - timeout=timeout, - timeout_callback=timeout_callback) + return self.xmpp['xep_0163'].publish( + reach, + node=Reachability.namespace, + **pubsubkwargs + ) - def stop(self, ifrom: Optional[JID] = None, - callback: Optional[Callable] = None, - timeout: Optional[int] = None, - timeout_callback: Optional[Callable] = None): + def stop(self, **pubsubkwargs) -> Future: """ Clear existing user activity information to stop notifications. """ reach = Reachability() - return self.xmpp['xep_0163'].publish(reach, - node=Reachability.namespace, - ifrom=ifrom, - callback=callback, - timeout=timeout, - timeout_callback=timeout_callback) + return self.xmpp['xep_0163'].publish( + reach, + node=Reachability.namespace, + **pubsubkwargs + )