From df963542c1183957660fc7d0254b7ac5fd7c5a93 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 3 Jul 2021 11:12:28 +0200 Subject: basexmpp/clientxmpp: refine typing --- slixmpp/basexmpp.py | 74 +++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) (limited to 'slixmpp/basexmpp.py') diff --git a/slixmpp/basexmpp.py b/slixmpp/basexmpp.py index 25aa0d75..0f01568e 100644 --- a/slixmpp/basexmpp.py +++ b/slixmpp/basexmpp.py @@ -45,10 +45,11 @@ log = logging.getLogger(__name__) from slixmpp.types import ( - PresenceShows, PresenceTypes, MessageTypes, IqTypes, + JidStr, + OptJidStr, ) if TYPE_CHECKING: @@ -314,8 +315,8 @@ class BaseXMPP(XMLStream): pres['lang'] = self.default_lang return pres - def make_iq(self, id: str = "0", ifrom: Optional[JID] = None, - ito: Optional[JID] = None, itype: Optional[IqTypes] = None, + def make_iq(self, id: str = "0", ifrom: OptJidStr = None, + ito: OptJidStr = None, itype: Optional[IqTypes] = None, iquery: Optional[str] = None) -> Iq: """Create a new :class:`~.Iq` stanza with a given Id and from JID. @@ -339,7 +340,7 @@ class BaseXMPP(XMLStream): return iq def make_iq_get(self, queryxmlns: Optional[str] =None, - ito: Optional[JID] = None, ifrom: Optional[JID] = None, + ito: OptJidStr = None, ifrom: OptJidStr = None, iq: Optional[Iq] = None) -> Iq: """Create an :class:`~.Iq` stanza of type ``'get'``. @@ -364,7 +365,7 @@ class BaseXMPP(XMLStream): return iq def make_iq_result(self, id: Optional[str] = None, - ito: Optional[JID] = None, ifrom: Optional[JID] = None, + ito: OptJidStr = None, ifrom: OptJidStr = None, iq: Optional[Iq] = None) -> Iq: """ Create an :class:`~.Iq` stanza of type @@ -391,7 +392,7 @@ class BaseXMPP(XMLStream): return iq def make_iq_set(self, sub: Optional[Union[ElementBase, ET.Element]] = None, - ito: Optional[JID] = None, ifrom: Optional[JID] = None, + ito: OptJidStr = None, ifrom: OptJidStr = None, iq: Optional[Iq] = None) -> Iq: """ Create an :class:`~.Iq` stanza of type ``'set'``. @@ -454,8 +455,8 @@ class BaseXMPP(XMLStream): return iq def make_iq_query(self, iq: Optional[Iq] = None, xmlns: str = '', - ito: Optional[JID] = None, - ifrom: Optional[JID] = None) -> Iq: + ito: OptJidStr = None, + ifrom: OptJidStr = None) -> Iq: """ Create or modify an :class:`~.Iq` stanza to use the given query namespace. @@ -487,10 +488,10 @@ class BaseXMPP(XMLStream): iq['query'] = 'jabber:iq:roster' return ET.Element("{jabber:iq:roster}query") - def make_message(self, mto: JID, mbody: Optional[str] = None, + def make_message(self, mto: JidStr, mbody: Optional[str] = None, msubject: Optional[str] = None, mtype: Optional[MessageTypes] = None, - mhtml: Optional[str] = None, mfrom: Optional[JID] = None, + mhtml: Optional[str] = None, mfrom: OptJidStr = None, mnick: Optional[str] = None) -> Message: """ Create and initialize a new @@ -516,12 +517,12 @@ class BaseXMPP(XMLStream): message['html']['body'] = mhtml return message - def make_presence(self, pshow: Optional[PresenceShows] = None, + def make_presence(self, pshow: Optional[str] = None, pstatus: Optional[str] = None, ppriority: Optional[int] = None, - pto: Optional[JID] = None, + pto: OptJidStr = None, ptype: Optional[PresenceTypes] = None, - pfrom: Optional[JID] = None, + pfrom: OptJidStr = None, pnick: Optional[str] = None) -> Presence: """ Create and initialize a new @@ -548,7 +549,7 @@ class BaseXMPP(XMLStream): def send_message(self, mto: JID, mbody: Optional[str] = None, msubject: Optional[str] = None, mtype: Optional[MessageTypes] = None, - mhtml: Optional[str] = None, mfrom: Optional[JID] = None, + mhtml: Optional[str] = None, mfrom: OptJidStr = None, mnick: Optional[str] = None): """ Create, initialize, and send a new @@ -568,12 +569,12 @@ class BaseXMPP(XMLStream): self.make_message(mto, mbody, msubject, mtype, mhtml, mfrom, mnick).send() - def send_presence(self, pshow: Optional[PresenceShows] = None, + def send_presence(self, pshow: Optional[str] = None, pstatus: Optional[str] = None, ppriority: Optional[int] = None, - pto: Optional[JID] = None, + pto: OptJidStr = None, ptype: Optional[PresenceTypes] = None, - pfrom: Optional[JID] = None, + pfrom: OptJidStr = None, pnick: Optional[str] = None): """ Create, initialize, and send a new @@ -590,8 +591,9 @@ class BaseXMPP(XMLStream): self.make_presence(pshow, pstatus, ppriority, pto, ptype, pfrom, pnick).send() - def send_presence_subscription(self, pto, pfrom=None, - ptype='subscribe', pnick=None): + def send_presence_subscription(self, pto: JidStr, pfrom: OptJidStr = None, + ptype: PresenceTypes='subscribe', pnick: + Optional[str] = None): """ Create, initialize, and send a new :class:`~.Presence` stanza of @@ -608,62 +610,62 @@ class BaseXMPP(XMLStream): pnick=pnick).send() @property - def jid(self): + def jid(self) -> str: """Attribute accessor for bare jid""" log.warning("jid property deprecated. Use boundjid.bare") return self.boundjid.bare @jid.setter - def jid(self, value): + def jid(self, value: str): log.warning("jid property deprecated. Use boundjid.bare") self.boundjid.bare = value @property - def fulljid(self): + def fulljid(self) -> str: """Attribute accessor for full jid""" log.warning("fulljid property deprecated. Use boundjid.full") return self.boundjid.full @fulljid.setter - def fulljid(self, value): + def fulljid(self, value: str): log.warning("fulljid property deprecated. Use boundjid.full") self.boundjid.full = value @property - def resource(self): + def resource(self) -> str: """Attribute accessor for jid resource""" log.warning("resource property deprecated. Use boundjid.resource") return self.boundjid.resource @resource.setter - def resource(self, value): + def resource(self, value: str): log.warning("fulljid property deprecated. Use boundjid.resource") self.boundjid.resource = value @property - def username(self): + def username(self) -> str: """Attribute accessor for jid usernode""" log.warning("username property deprecated. Use boundjid.user") return self.boundjid.user @username.setter - def username(self, value): + def username(self, value: str): log.warning("username property deprecated. Use boundjid.user") self.boundjid.user = value @property - def server(self): + def server(self) -> str: """Attribute accessor for jid host""" log.warning("server property deprecated. Use boundjid.host") return self.boundjid.server @server.setter - def server(self, value): + def server(self, value: str): log.warning("server property deprecated. Use boundjid.host") self.boundjid.server = value @property - def auto_authorize(self): + def auto_authorize(self) -> Optional[bool]: """Auto accept or deny subscription requests. If ``True``, auto accept subscription requests. @@ -673,11 +675,11 @@ class BaseXMPP(XMLStream): return self.roster.auto_authorize @auto_authorize.setter - def auto_authorize(self, value): + def auto_authorize(self, value: Optional[bool]): self.roster.auto_authorize = value @property - def auto_subscribe(self): + def auto_subscribe(self) -> bool: """Auto send requests for mutual subscriptions. If ``True``, auto send mutual subscription requests. @@ -685,21 +687,21 @@ class BaseXMPP(XMLStream): return self.roster.auto_subscribe @auto_subscribe.setter - def auto_subscribe(self, value): + def auto_subscribe(self, value: bool): self.roster.auto_subscribe = value - def set_jid(self, jid): + def set_jid(self, jid: JidStr): """Rip a JID apart and claim it as our own.""" log.debug("setting jid to %s", jid) self.boundjid = JID(jid) - def getjidresource(self, fulljid): + def getjidresource(self, fulljid: str): if '/' in fulljid: return fulljid.split('/', 1)[-1] else: return '' - def getjidbare(self, fulljid): + def getjidbare(self, fulljid: str): return fulljid.split('/', 1)[0] def _handle_session_start(self, event): -- cgit v1.2.3